DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities
@ 2019-09-06 22:09 Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
                   ` (9 more replies)
  0 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

This patchset includes additional functionalities to Windows EAL
to support command-line parsing feature and EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

Pallavi Kadam (9):
  eal: eal stub to support parsing feature on windows
  eal: syslog implementation for windows
  eal: add windows compatible header files
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/include/rte_lcore.h     |   5 +
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 132 ++++
 lib/librte_eal/windows/eal/getopt_long.c      | 196 ++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 666 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   |  59 ++
 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/rte_vect.h |   9 +
 lib/librte_eal/windows/eal/include/sched.h    |  58 +-
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/include/syslog.h   | 213 ++++++
 lib/librte_eal/windows/eal/meson.build        |  10 +-
 16 files changed, 1755 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows Pallavi Kadam
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding initial stub to support command line parsing
for lcore mask option on Windows.

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/windows/eal/eal.c        | 29 ++++++++++++++++++++++---
 lib/librte_eal/windows/eal/eal_thread.c |  8 +++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..83907ffa6 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -24,6 +24,23 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+}
+
+/* Parse the argument given in the command line of the application */
+static int
+eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+	return 0;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -39,9 +56,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -52,6 +71,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -80,5 +103,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 906502f90..6e5e6f4ab 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -151,3 +151,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files Pallavi Kadam
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding syslog.h on Windows for supporting common code.
This implementation has BSD-3-Clause licensing.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/syslog.h | 213 ++++++++++++++++++++
 1 file changed, 213 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

diff --git a/lib/librte_eal/windows/eal/include/syslog.h b/lib/librte_eal/windows/eal/include/syslog.h
new file mode 100644
index 000000000..ba3129c5f
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/syslog.h
@@ -0,0 +1,213 @@
+/* Copyright (c) 1982, 1986, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)syslog.h	8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_SYSLOG_H
+#define _SYS_SYSLOG_H 1
+
+#include <stdarg.h>
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number).  Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code.  This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+#define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
+/* extract priority */
+#define	LOG_PRI(p)	((p) & LOG_PRIMASK)
+#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
+
+#ifdef SYSLOG_NAMES
+#define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
+/* mark "facility" */
+#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
+typedef struct _code {
+	char	*c_name;
+	int	c_val;
+} CODE;
+
+CODE prioritynames[] = {
+	{ "alert", LOG_ALERT },
+	{ "crit", LOG_CRIT },
+	{ "debug", LOG_DEBUG },
+	{ "emerg", LOG_EMERG },
+	{ "err", LOG_ERR },
+	{ "error", LOG_ERR },		/* DEPRECATED */
+	{ "info", LOG_INFO },
+	{ "none", INTERNAL_NOPRI },		/* INTERNAL */
+	{ "notice", LOG_NOTICE },
+	{ "panic", LOG_EMERG },		/* DEPRECATED */
+	{ "warn", LOG_WARNING },		/* DEPRECATED */
+	{ "warning", LOG_WARNING },
+	{ NULL, -1 }
+};
+#endif
+
+/* facility codes */
+#define	LOG_KERN	(0<<3)	/* kernel messages */
+#define	LOG_USER	(1<<3)	/* random user-level messages */
+#define	LOG_MAIL	(2<<3)	/* mail system */
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
+#define	LOG_CRON	(9<<3)	/* clock daemon */
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
+
+/* other codes through 15 reserved for system use */
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
+
+#define	LOG_NFACILITIES	24	/* current number of facilities */
+#define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
+/* facility of pri */
+#define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+	{ "auth", LOG_AUTH },
+	{ "authpriv", LOG_AUTHPRIV },
+	{ "cron", LOG_CRON },
+	{ "daemon", LOG_DAEMON },
+	{ "ftp", LOG_FTP },
+	{ "kern", LOG_KERN },
+	{ "lpr", LOG_LPR },
+	{ "mail", LOG_MAIL },
+	{ "mark", INTERNAL_MARK },		/* INTERNAL */
+	{ "news", LOG_NEWS },
+	{ "security", LOG_AUTH },		/* DEPRECATED */
+	{ "syslog", LOG_SYSLOG },
+	{ "user", LOG_USER },
+	{ "uucp", LOG_UUCP },
+	{ "local0", LOG_LOCAL0 },
+	{ "local1", LOG_LOCAL1 },
+	{ "local2", LOG_LOCAL2 },
+	{ "local3", LOG_LOCAL3 },
+	{ "local4", LOG_LOCAL4 },
+	{ "local5", LOG_LOCAL5 },
+	{ "local6", LOG_LOCAL6 },
+	{ "local7", LOG_LOCAL7 },
+	{ NULL, -1 }
+};
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
+#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define	LOG_PID		0x01	/* log the pid with each message */
+#define	LOG_CONS	0x02	/* log on the console if errors in sending */
+#define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
+#define	LOG_NDELAY	0x08	/* don't delay open */
+#define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
+#define	LOG_PERROR	0x20	/* log to stderr as well */
+
+#define SYSLOG_PORT     514
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Close desriptor used to write to system logger.  */
+extern void closelog(void);
+
+/* Open connection to system logger.  */
+extern void openlog(char *__ident, int __option, int __facility);
+
+/* Set the log mask level.  */
+extern int setlogmask(int __mask);
+
+/* Generate a log message using FMT string and option arguments. */
+extern void syslog(int __pri, char *__fmt, ...);
+
+/* Generate a log message using FMT and using arguments pointed to by AP. */
+extern void vsyslog(int __pri, char *__fmt, va_list __ap);
+
+#ifdef _WIN32
+/* Windows specific.
+ *
+ *init_syslog() *must* be called before calling any of the above
+ *functions.  exit_syslog() will be scheduled using atexit().
+ *However, it is not an error and encouraged to call
+ *exit_syslog() before the application exits.
+ *
+ *During operation, the application is free to call exit_syslog()
+ *followed by init_syslog() to re-initialize the library. i.e. if
+ *a different syslog host is to be used.
+ */
+
+/* Initializes the syslog library and sets the syslog host.  The
+ * hostname parameter is of the form "<hostname>[:<port>]".  The
+ * <port> may be a numeric port or it may be a name of a service.
+ * If the <port> is specified using a service name, it will be
+ * looked up using getservbyname().
+ *
+ * On failure, the hostname and port will be set to "localhost"
+ * and SYSLOG_PORT respectively.
+ */
+extern void init_syslog(const char *hostname);
+
+extern void exit_syslog(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* syslog.h */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows Pallavi Kadam
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain; charset=UTF-8, Size: 7437 bytes --]

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Adding getopt.h to support parsing options on Windows.

Adding rte_vect.h as Windows fails to compile:
\common\include\arch\x86\rte_vect.h.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dlfcn.h    | 21 ++++
 .../windows/eal/include/eal_filesystem.h      | 99 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   | 59 +++++++++++
 lib/librte_eal/windows/eal/include/rte_vect.h |  9 ++
 4 files changed, 188 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h

diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..e7382d7d5
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,59 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright © 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _GETOPT_H
+#define _GETOPT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int getopt(int, char * const [], const char *);
+extern char *optarg;
+extern int optind, opterr, optopt, optreset;
+
+struct option {
+	const char *name;
+	int has_arg;
+	int *flag;
+	int val;
+};
+
+void __getopt_msg(const char *a, const char *b, const char *c, size_t l);
+
+int getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+int getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+
+#define no_argument        0
+#define required_argument  1
+#define optional_argument  2
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
new file mode 100644
index 000000000..630473e28
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/rte_vect.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#pragma once
+
+#define __ICC	1600
+
+#include "..\..\common\include\arch\x86\rte_vect.h"
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (2 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding dirent.h on Windows to support common code.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 666 ++++++++++++++++++++
 1 file changed, 666 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..577be25b6
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,666 @@
+/* Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ *
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * This file is part of dirent.  Dirent may be freely distributed
+ * under the MIT license.  For all details and documentation, see
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occured
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (3 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows Pallavi Kadam
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

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(-)

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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (4 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 7/9] eal: add function to detect process type Pallavi Kadam
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain; charset=UTF-8, Size: 10062 bytes --]

Adding getopt_long.c and getopt.c files to support parsing
option on Windows.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c      | 132 +++++++++++++++
 lib/librte_eal/windows/eal/getopt_long.c | 196 +++++++++++++++++++++++
 lib/librte_eal/windows/eal/meson.build   |   2 +
 3 files changed, 330 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..6c619107b
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,132 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright © 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <wchar.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+char *optarg;
+int optind = 1, opterr = 1, optopt, __optpos, __optreset = 0;
+
+#define optpos __optpos
+
+void
+__getopt_msg(const char *a, const char *b, const char *c, size_t l)
+{
+	FILE *f = stderr;
+	fputs(a, f) >= 0
+	&& fwrite(b, strlen(b), 1, f)
+	&& fwrite(c, 1, l, f) == l
+	&& putc('\n', f);
+}
+
+int
+getopt(int argc, char * const argv[], const char *optstring)
+{
+	int i;
+	wchar_t c, d;
+	int k, l;
+	char *optchar;
+
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+
+	if (optind >= argc || !argv[optind])
+		return -1;
+
+	if (argv[optind][0] != '-') {
+		if (optstring[0] == '-') {
+			optarg = argv[optind++];
+			return 1;
+		}
+		return -1;
+	}
+
+	if (!argv[optind][1])
+		return -1;
+
+	if (argv[optind][1] == '-' && !argv[optind][2])
+		return optind++, -1;
+
+	if (!optpos)
+		optpos++;
+	k = mbtowc(&c, argv[optind] + optpos, MB_LEN_MAX);
+	if (k < 0) {
+		k = 1;
+		c = 0xfffd; /* replacement char */
+	}
+	optchar = argv[optind]+optpos;
+	optpos += k;
+
+	if (!argv[optind][optpos]) {
+		optind++;
+		optpos = 0;
+	}
+
+	if (optstring[0] == '-' || optstring[0] == '+')
+		optstring++;
+
+	i = 0;
+	d = 0;
+	do {
+		l = mbtowc(&d, optstring+i, MB_LEN_MAX);
+		if (l > 0)
+			i += l;
+		else
+			i++;
+	} while (l && d != c);
+
+	if (d != c || c == ':') {
+		optopt = c;
+		if (optstring[0] != ':' && opterr)
+			__getopt_msg(argv[0], ": unrecognized option: ",
+				optchar, k);
+		return '?';
+	}
+	if (optstring[i] == ':') {
+		optarg = 0;
+		if (optstring[i+1] != ':' || optpos) {
+			optarg = argv[optind++] + optpos;
+			optpos = 0;
+		}
+		if (optind > argc) {
+			optopt = c;
+			if (optstring[0] == ':')
+				return ':';
+			if (opterr)
+				__getopt_msg(argv[0],
+				": option requires an argument: ",
+				optchar, k);
+			return '?';
+		}
+	}
+	return c;
+}
diff --git a/lib/librte_eal/windows/eal/getopt_long.c b/lib/librte_eal/windows/eal/getopt_long.c
new file mode 100644
index 000000000..3877acbe9
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt_long.c
@@ -0,0 +1,196 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright © 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int __optpos, __optreset;
+
+static void
+permute(char **argv, int dest, int src)
+{
+	char **av = (char **)argv;
+	char *tmp = av[src];
+	int i;
+	for (i = src; i > dest; i--)
+		av[i] = av[i-1];
+	av[dest] = tmp;
+}
+
+static int __getopt_long_core(int argc, char **argv,
+	const char *optstring, const struct option *longopts,
+	int *idx, int longonly);
+
+static int
+__getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	int ret, skipped, resumed;
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+	if (optind >= argc || !argv[optind])
+		return -1;
+	skipped = optind;
+	if (optstring[0] != '+' && optstring[0] != '-') {
+		int i;
+		for (i = optind; ; i++) {
+			if (i >= argc || !argv[i])
+				return -1;
+			if (argv[i][0] == '-' && argv[i][1])
+				break;
+		}
+		optind = i;
+	}
+	resumed = optind;
+	ret = __getopt_long_core(argc, argv, optstring, longopts,
+		idx, longonly);
+	if (resumed > skipped) {
+		int i, cnt = optind-resumed;
+		for (i = 0; i < cnt; i++)
+			permute(argv, skipped, optind-1);
+		optind = skipped + cnt;
+	}
+	return ret;
+}
+
+static int
+__getopt_long_core(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	optarg = 0;
+	if (longopts && argv[optind][0] == '-' &&
+		((longonly && argv[optind][1] && argv[optind][1] != '-') ||
+		 (argv[optind][1] == '-' && argv[optind][2]))) {
+
+		int colon = optstring[optstring[0] == '+' || optstring[0] ==
+			'-'] == ':';
+		int i, cnt, match;
+		char *arg, *opt, *start = argv[optind]+1;
+		for (cnt = i = 0; longopts[i].name; i++) {
+			const char *name = longopts[i].name;
+			opt = start;
+			if (*opt == '-')
+				opt++;
+			while (*opt && *opt != '=' && *opt == *name)
+				name++, opt++;
+			if (*opt && *opt != '=')
+				continue;
+			arg = opt;
+			match = i;
+			if (!*name) {
+				cnt = 1;
+				break;
+			}
+			cnt++;
+		}
+		if (cnt == 1 && longonly && arg-start ==
+			mblen(start, MB_LEN_MAX)) {
+			int l = arg - start;
+			for (i = 0; optstring[i]; i++) {
+				int j;
+				for (j = 0; j < l && start[j] ==
+					optstring[i + j]; j++)
+					;
+				if (j == l) {
+					cnt++;
+					break;
+				}
+			}
+		}
+		if (cnt == 1) {
+			i = match;
+			opt = arg;
+			optind++;
+			if (*opt == '=') {
+				if (!longopts[i].has_arg) {
+					optopt = longopts[i].val;
+					if (colon || !opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option does not take an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optarg = opt+1;
+			} else if (longopts[i].has_arg == required_argument) {
+				optarg = argv[optind];
+				if (!optarg) {
+					optopt = longopts[i].val;
+					if (colon)
+						return ':';
+					if (!opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option requires an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optind++;
+			}
+			if (idx)
+				*idx = i;
+			if (longopts[i].flag) {
+				*longopts[i].flag = longopts[i].val;
+				return 0;
+			}
+			return longopts[i].val;
+		}
+		if (argv[optind][1] == '-') {
+			optopt = 0;
+			if (!colon && opterr)
+				__getopt_msg(argv[0], cnt ?
+					": option is ambiguous: " :
+					": unrecognized option: ",
+					argv[optind]+2,
+					strlen(argv[optind]+2));
+			optind++;
+			return '?';
+		}
+	}
+	return getopt(argc, argv, optstring);
+}
+
+int
+getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 0);
+}
+
+int
+getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 1);
+}
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..aa29e2e97 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,6 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
+	'getopt_long.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 7/9] eal: add function to detect process type
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (5 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 8/9] build: add additional common files support Pallavi Kadam
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding a function to detect process type and include
header files to contain suitable function declarations.

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/windows/eal/eal.c        | 51 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_thread.c |  3 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 83907ffa6..ffe5b8552 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,38 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1; // INVALID_HANDLE_VALUE;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +41,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+	eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 6e5e6f4ab..54b9c1dd1 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,10 +10,13 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 8/9] build: add additional common files support
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (6 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 7/9] eal: add function to detect process type Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index aa29e2e97..40c04590f 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (7 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 8/9] build: add additional common files support Pallavi Kadam
@ 2019-09-06 22:09 ` Pallavi Kadam
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-06 22:09 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 119 +++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ffe5b8552..8deb6c83a 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -13,8 +13,12 @@
 #include <eal_thread.h>
 #include <eal_internal_cfg.h>
 #include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -73,21 +77,122 @@ enum rte_proc_type_t
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
 /* Parse the arguments for --log-level only */
 static void
-eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+eal_log_level_parse(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
 }
 
 /* Parse the argument given in the command line of the application */
 static int
-eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+eal_parse_args(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
-	return 0;
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
 }
 
 static int
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities
  2019-09-06 22:09 [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                   ` (8 preceding siblings ...)
  2019-09-06 22:09 ` [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2019-09-09 19:53 ` Pallavi Kadam
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
                     ` (9 more replies)
  9 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:53 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

Pallavi Kadam (9):
  eal: eal stub to support parsing feature on windows
  eal: syslog implementation for windows
  eal: add windows compatible header files
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/include/rte_lcore.h     |   5 +
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 132 ++++
 lib/librte_eal/windows/eal/getopt_long.c      | 196 ++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 666 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   |  59 ++
 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/rte_vect.h |   9 +
 lib/librte_eal/windows/eal/include/sched.h    |  58 +-
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/include/syslog.h   | 213 ++++++
 lib/librte_eal/windows/eal/meson.build        |  10 +-
 16 files changed, 1755 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2019-09-09 19:53   ` Pallavi Kadam
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows Pallavi Kadam
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:53 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding initial stub to support command line parsing
for lcore mask option on Windows.

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/windows/eal/eal.c        | 29 ++++++++++++++++++++++---
 lib/librte_eal/windows/eal/eal_thread.c |  8 +++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..83907ffa6 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -24,6 +24,23 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+}
+
+/* Parse the argument given in the command line of the application */
+static int
+eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+	return 0;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -39,9 +56,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -52,6 +71,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -80,5 +103,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 906502f90..6e5e6f4ab 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -151,3 +151,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
@ 2019-09-09 19:53   ` Pallavi Kadam
  2019-09-10  9:17     ` Stephen Hemminger
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files Pallavi Kadam
                     ` (7 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:53 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding syslog.h on Windows for supporting common code.
This implementation has BSD-3-Clause licensing.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/syslog.h | 213 ++++++++++++++++++++
 1 file changed, 213 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

diff --git a/lib/librte_eal/windows/eal/include/syslog.h b/lib/librte_eal/windows/eal/include/syslog.h
new file mode 100644
index 000000000..57306e921
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/syslog.h
@@ -0,0 +1,213 @@
+/* Copyright (c) 1982, 1986, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	syslog.h	8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_SYSLOG_H
+#define _SYS_SYSLOG_H 1
+
+#include <stdarg.h>
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number).  Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code.  This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+#define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
+/* extract priority */
+#define	LOG_PRI(p)	((p) & LOG_PRIMASK)
+#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
+
+#ifdef SYSLOG_NAMES
+#define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
+/* mark "facility" */
+#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
+typedef struct _code {
+	char	*c_name;
+	int	c_val;
+} CODE;
+
+CODE prioritynames[] = {
+	{ "alert", LOG_ALERT },
+	{ "crit", LOG_CRIT },
+	{ "debug", LOG_DEBUG },
+	{ "emerg", LOG_EMERG },
+	{ "err", LOG_ERR },
+	{ "error", LOG_ERR },		/* DEPRECATED */
+	{ "info", LOG_INFO },
+	{ "none", INTERNAL_NOPRI },		/* INTERNAL */
+	{ "notice", LOG_NOTICE },
+	{ "panic", LOG_EMERG },		/* DEPRECATED */
+	{ "warn", LOG_WARNING },		/* DEPRECATED */
+	{ "warning", LOG_WARNING },
+	{ NULL, -1 }
+};
+#endif
+
+/* facility codes */
+#define	LOG_KERN	(0<<3)	/* kernel messages */
+#define	LOG_USER	(1<<3)	/* random user-level messages */
+#define	LOG_MAIL	(2<<3)	/* mail system */
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
+#define	LOG_CRON	(9<<3)	/* clock daemon */
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
+
+/* other codes through 15 reserved for system use */
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
+
+#define	LOG_NFACILITIES	24	/* current number of facilities */
+#define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
+/* facility of pri */
+#define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+	{ "auth", LOG_AUTH },
+	{ "authpriv", LOG_AUTHPRIV },
+	{ "cron", LOG_CRON },
+	{ "daemon", LOG_DAEMON },
+	{ "ftp", LOG_FTP },
+	{ "kern", LOG_KERN },
+	{ "lpr", LOG_LPR },
+	{ "mail", LOG_MAIL },
+	{ "mark", INTERNAL_MARK },		/* INTERNAL */
+	{ "news", LOG_NEWS },
+	{ "security", LOG_AUTH },		/* DEPRECATED */
+	{ "syslog", LOG_SYSLOG },
+	{ "user", LOG_USER },
+	{ "uucp", LOG_UUCP },
+	{ "local0", LOG_LOCAL0 },
+	{ "local1", LOG_LOCAL1 },
+	{ "local2", LOG_LOCAL2 },
+	{ "local3", LOG_LOCAL3 },
+	{ "local4", LOG_LOCAL4 },
+	{ "local5", LOG_LOCAL5 },
+	{ "local6", LOG_LOCAL6 },
+	{ "local7", LOG_LOCAL7 },
+	{ NULL, -1 }
+};
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
+#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define	LOG_PID		0x01	/* log the pid with each message */
+#define	LOG_CONS	0x02	/* log on the console if errors in sending */
+#define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
+#define	LOG_NDELAY	0x08	/* don't delay open */
+#define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
+#define	LOG_PERROR	0x20	/* log to stderr as well */
+
+#define SYSLOG_PORT     514
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Close descriptor used to write to system logger.  */
+extern void closelog(void);
+
+/* Open connection to system logger.  */
+extern void openlog(char *__ident, int __option, int __facility);
+
+/* Set the log mask level.  */
+extern int setlogmask(int __mask);
+
+/* Generate a log message using FMT string and option arguments. */
+extern void syslog(int __pri, char *__fmt, ...);
+
+/* Generate a log message using FMT and using arguments pointed to by AP. */
+extern void vsyslog(int __pri, char *__fmt, va_list __ap);
+
+#ifdef _WIN32
+/* Windows specific.
+ *
+ *init_syslog() *must* be called before calling any of the above
+ *functions.  exit_syslog() will be scheduled using atexit().
+ *However, it is not an error and encouraged to call
+ *exit_syslog() before the application exits.
+ *
+ *During operation, the application is free to call exit_syslog()
+ *followed by init_syslog() to re-initialize the library. i.e. if
+ *a different syslog host is to be used.
+ */
+
+/* Initializes the syslog library and sets the syslog host.  The
+ * hostname parameter is of the form "<hostname>[:<port>]".  The
+ * <port> may be a numeric port or it may be a name of a service.
+ * If the <port> is specified using a service name, it will be
+ * looked up using getservbyname().
+ *
+ * On failure, the hostname and port will be set to "localhost"
+ * and SYSLOG_PORT respectively.
+ */
+extern void init_syslog(const char *hostname);
+
+extern void exit_syslog(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* syslog.h */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows Pallavi Kadam
@ 2019-09-09 19:53   ` Pallavi Kadam
  2019-09-10  9:19     ` Stephen Hemminger
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows Pallavi Kadam
                     ` (6 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:53 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Adding getopt.h to support parsing options on Windows.

Adding rte_vect.h as Windows fails to compile:
\common\include\arch\x86\rte_vect.h.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dlfcn.h    | 21 ++++
 .../windows/eal/include/eal_filesystem.h      | 99 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   | 59 +++++++++++
 lib/librte_eal/windows/eal/include/rte_vect.h |  9 ++
 4 files changed, 188 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h

diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..d47202ec9
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,59 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _GETOPT_H
+#define _GETOPT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int getopt(int, char * const [], const char *);
+extern char *optarg;
+extern int optind, opterr, optopt, optreset;
+
+struct option {
+	const char *name;
+	int has_arg;
+	int *flag;
+	int val;
+};
+
+void __getopt_msg(const char *a, const char *b, const char *c, size_t l);
+
+int getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+int getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+
+#define no_argument        0
+#define required_argument  1
+#define optional_argument  2
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
new file mode 100644
index 000000000..630473e28
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/rte_vect.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#pragma once
+
+#define __ICC	1600
+
+#include "..\..\common\include\arch\x86\rte_vect.h"
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (2 preceding siblings ...)
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-09-09 19:53   ` Pallavi Kadam
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:53 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding dirent.h on Windows to support common code.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 666 ++++++++++++++++++++
 1 file changed, 666 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..1687e2d85
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,666 @@
+/* Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ *
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * This file is part of dirent.  Dirent may be freely distributed
+ * under the MIT license.  For all details and documentation, see
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (3 preceding siblings ...)
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows Pallavi Kadam
@ 2019-09-09 19:54   ` Pallavi Kadam
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows Pallavi Kadam
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:54 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

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(-)

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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (4 preceding siblings ...)
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2019-09-09 19:54   ` Pallavi Kadam
  2019-09-12 21:40     ` Stephen Hemminger
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 7/9] eal: add function to detect process type Pallavi Kadam
                     ` (3 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:54 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding getopt_long.c and getopt.c files to support parsing
option on Windows.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c      | 132 +++++++++++++++
 lib/librte_eal/windows/eal/getopt_long.c | 196 +++++++++++++++++++++++
 lib/librte_eal/windows/eal/meson.build   |   2 +
 3 files changed, 330 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..760c00eef
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,132 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <wchar.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+char *optarg;
+int optind = 1, opterr = 1, optopt, __optpos, __optreset = 0;
+
+#define optpos __optpos
+
+void
+__getopt_msg(const char *a, const char *b, const char *c, size_t l)
+{
+	FILE *f = stderr;
+	fputs(a, f) >= 0
+	&& fwrite(b, strlen(b), 1, f)
+	&& fwrite(c, 1, l, f) == l
+	&& putc('\n', f);
+}
+
+int
+getopt(int argc, char * const argv[], const char *optstring)
+{
+	int i;
+	wchar_t c, d;
+	int k, l;
+	char *optchar;
+
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+
+	if (optind >= argc || !argv[optind])
+		return -1;
+
+	if (argv[optind][0] != '-') {
+		if (optstring[0] == '-') {
+			optarg = argv[optind++];
+			return 1;
+		}
+		return -1;
+	}
+
+	if (!argv[optind][1])
+		return -1;
+
+	if (argv[optind][1] == '-' && !argv[optind][2])
+		return optind++, -1;
+
+	if (!optpos)
+		optpos++;
+	k = mbtowc(&c, argv[optind] + optpos, MB_LEN_MAX);
+	if (k < 0) {
+		k = 1;
+		c = 0xfffd; /* replacement char */
+	}
+	optchar = argv[optind]+optpos;
+	optpos += k;
+
+	if (!argv[optind][optpos]) {
+		optind++;
+		optpos = 0;
+	}
+
+	if (optstring[0] == '-' || optstring[0] == '+')
+		optstring++;
+
+	i = 0;
+	d = 0;
+	do {
+		l = mbtowc(&d, optstring+i, MB_LEN_MAX);
+		if (l > 0)
+			i += l;
+		else
+			i++;
+	} while (l && d != c);
+
+	if (d != c || c == ':') {
+		optopt = c;
+		if (optstring[0] != ':' && opterr)
+			__getopt_msg(argv[0], ": unrecognized option: ",
+				optchar, k);
+		return '?';
+	}
+	if (optstring[i] == ':') {
+		optarg = 0;
+		if (optstring[i+1] != ':' || optpos) {
+			optarg = argv[optind++] + optpos;
+			optpos = 0;
+		}
+		if (optind > argc) {
+			optopt = c;
+			if (optstring[0] == ':')
+				return ':';
+			if (opterr)
+				__getopt_msg(argv[0],
+				": option requires an argument: ",
+				optchar, k);
+			return '?';
+		}
+	}
+	return c;
+}
diff --git a/lib/librte_eal/windows/eal/getopt_long.c b/lib/librte_eal/windows/eal/getopt_long.c
new file mode 100644
index 000000000..583190783
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt_long.c
@@ -0,0 +1,196 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int __optpos, __optreset;
+
+static void
+permute(char **argv, int dest, int src)
+{
+	char **av = (char **)argv;
+	char *tmp = av[src];
+	int i;
+	for (i = src; i > dest; i--)
+		av[i] = av[i-1];
+	av[dest] = tmp;
+}
+
+static int __getopt_long_core(int argc, char **argv,
+	const char *optstring, const struct option *longopts,
+	int *idx, int longonly);
+
+static int
+__getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	int ret, skipped, resumed;
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+	if (optind >= argc || !argv[optind])
+		return -1;
+	skipped = optind;
+	if (optstring[0] != '+' && optstring[0] != '-') {
+		int i;
+		for (i = optind; ; i++) {
+			if (i >= argc || !argv[i])
+				return -1;
+			if (argv[i][0] == '-' && argv[i][1])
+				break;
+		}
+		optind = i;
+	}
+	resumed = optind;
+	ret = __getopt_long_core(argc, argv, optstring, longopts,
+		idx, longonly);
+	if (resumed > skipped) {
+		int i, cnt = optind-resumed;
+		for (i = 0; i < cnt; i++)
+			permute(argv, skipped, optind-1);
+		optind = skipped + cnt;
+	}
+	return ret;
+}
+
+static int
+__getopt_long_core(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	optarg = 0;
+	if (longopts && argv[optind][0] == '-' &&
+		((longonly && argv[optind][1] && argv[optind][1] != '-') ||
+		 (argv[optind][1] == '-' && argv[optind][2]))) {
+
+		int colon = optstring[optstring[0] == '+' || optstring[0] ==
+			'-'] == ':';
+		int i, cnt, match;
+		char *arg, *opt, *start = argv[optind]+1;
+		for (cnt = i = 0; longopts[i].name; i++) {
+			const char *name = longopts[i].name;
+			opt = start;
+			if (*opt == '-')
+				opt++;
+			while (*opt && *opt != '=' && *opt == *name)
+				name++, opt++;
+			if (*opt && *opt != '=')
+				continue;
+			arg = opt;
+			match = i;
+			if (!*name) {
+				cnt = 1;
+				break;
+			}
+			cnt++;
+		}
+		if (cnt == 1 && longonly && arg-start ==
+			mblen(start, MB_LEN_MAX)) {
+			int l = arg - start;
+			for (i = 0; optstring[i]; i++) {
+				int j;
+				for (j = 0; j < l && start[j] ==
+					optstring[i + j]; j++)
+					;
+				if (j == l) {
+					cnt++;
+					break;
+				}
+			}
+		}
+		if (cnt == 1) {
+			i = match;
+			opt = arg;
+			optind++;
+			if (*opt == '=') {
+				if (!longopts[i].has_arg) {
+					optopt = longopts[i].val;
+					if (colon || !opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option does not take an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optarg = opt+1;
+			} else if (longopts[i].has_arg == required_argument) {
+				optarg = argv[optind];
+				if (!optarg) {
+					optopt = longopts[i].val;
+					if (colon)
+						return ':';
+					if (!opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option requires an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optind++;
+			}
+			if (idx)
+				*idx = i;
+			if (longopts[i].flag) {
+				*longopts[i].flag = longopts[i].val;
+				return 0;
+			}
+			return longopts[i].val;
+		}
+		if (argv[optind][1] == '-') {
+			optopt = 0;
+			if (!colon && opterr)
+				__getopt_msg(argv[0], cnt ?
+					": option is ambiguous: " :
+					": unrecognized option: ",
+					argv[optind]+2,
+					strlen(argv[optind]+2));
+			optind++;
+			return '?';
+		}
+	}
+	return getopt(argc, argv, optstring);
+}
+
+int
+getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 0);
+}
+
+int
+getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 1);
+}
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..aa29e2e97 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,6 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
+	'getopt_long.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 7/9] eal: add function to detect process type
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (5 preceding siblings ...)
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-09-09 19:54   ` Pallavi Kadam
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 8/9] build: add additional common files support Pallavi Kadam
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:54 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding a function to detect process type and include
header files to contain suitable function declarations.

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/windows/eal/eal.c        | 51 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_thread.c |  3 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 83907ffa6..ffe5b8552 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,38 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1; // INVALID_HANDLE_VALUE;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +41,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+	eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 6e5e6f4ab..54b9c1dd1 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,10 +10,13 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 8/9] build: add additional common files support
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (6 preceding siblings ...)
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 7/9] eal: add function to detect process type Pallavi Kadam
@ 2019-09-09 19:54   ` Pallavi Kadam
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:54 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index aa29e2e97..40c04590f 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (7 preceding siblings ...)
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 8/9] build: add additional common files support Pallavi Kadam
@ 2019-09-09 19:54   ` Pallavi Kadam
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-09 19:54 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, ranjit.menon, keith.wiles, bruce.richardson,
	antara.ganesh.kolar, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 119 +++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ffe5b8552..8deb6c83a 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -13,8 +13,12 @@
 #include <eal_thread.h>
 #include <eal_internal_cfg.h>
 #include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -73,21 +77,122 @@ enum rte_proc_type_t
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
 /* Parse the arguments for --log-level only */
 static void
-eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+eal_log_level_parse(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
 }
 
 /* Parse the argument given in the command line of the application */
 static int
-eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+eal_parse_args(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
-	return 0;
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
 }
 
 static int
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows Pallavi Kadam
@ 2019-09-10  9:17     ` Stephen Hemminger
  2019-09-25 23:38       ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Stephen Hemminger @ 2019-09-10  9:17 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, ranjit.menon, keith.wiles,
	bruce.richardson, antara.ganesh.kolar

On Mon,  9 Sep 2019 12:53:57 -0700
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

> +/* Copyright (c) 1982, 1986, 1988, 1993
> + *	The Regents of the University of California.  All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 4. Neither the name of the University nor the names of its contributors
> + *    may be used to endorse or promote products derived from this software
> + *    without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

All code must have SPDX license tag and not boiler plate text.
It should not be merged in current state.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files
  2019-09-09 19:53   ` [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-09-10  9:19     ` Stephen Hemminger
  2019-09-12 17:11       ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Stephen Hemminger @ 2019-09-10  9:19 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, ranjit.menon, keith.wiles,
	bruce.richardson, antara.ganesh.kolar

On Mon,  9 Sep 2019 12:53:58 -0700
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

> --- /dev/null
> +++ b/lib/librte_eal/windows/eal/include/getopt.h
> @@ -0,0 +1,59 @@
> +/* musl as a whole is licensed under the following standard MIT license:
> + *
> + * ----------------------------------------------------------------------
> + * Copyright (c) 2005-2014 Rich Felker, et al.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining
> + * a copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sublicense, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> + * included in all copies or substantial portions of the Software.
> + *

Although MIT license is similar to BSD license, it is not the same.
The DPDK project has converged to only use BSD-3 for all DPDK code (and GPL for kernel code).

Please find an alternative that is BSD licensed.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files
  2019-09-10  9:19     ` Stephen Hemminger
@ 2019-09-12 17:11       ` Pallavi Kadam
  2019-09-12 21:36         ` Stephen Hemminger
  0 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-12 17:11 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, thomas, Harini.Ramakrishnan, ranjit.menon, keith.wiles,
	bruce.richardson, antara.ganesh.kolar


On 9/10/2019 2:19 AM, Stephen Hemminger wrote:
> On Mon,  9 Sep 2019 12:53:58 -0700
> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
>> --- /dev/null
>> +++ b/lib/librte_eal/windows/eal/include/getopt.h
>> @@ -0,0 +1,59 @@
>> +/* musl as a whole is licensed under the following standard MIT license:
>> + *
>> + * ----------------------------------------------------------------------
>> + * Copyright (c) 2005-2014 Rich Felker, et al.
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining
>> + * a copy of this software and associated documentation files (the
>> + * "Software"), to deal in the Software without restriction, including
>> + * without limitation the rights to use, copy, modify, merge, publish,
>> + * distribute, sublicense, and/or sell copies of the Software, and to
>> + * permit persons to whom the Software is furnished to do so, subject to
>> + * the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be
>> + * included in all copies or substantial portions of the Software.
>> + *
> Although MIT license is similar to BSD license, it is not the same.
> The DPDK project has converged to only use BSD-3 for all DPDK code (and GPL for kernel code).
>
> Please find an alternative that is BSD licensed.

We discussed in the Windows Community call regarding the challenges we 
are facing to find and include

BSD-3 implementation of getopt and dirent files.

Please let us know if there can be any exceptions to include MIT license 
code for Windows

as mentionedin dpdk.org charter under 6.3 section.

Thomas, can you please comment on this?


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files
  2019-09-12 17:11       ` Pallavi Kadam
@ 2019-09-12 21:36         ` Stephen Hemminger
  0 siblings, 0 replies; 149+ messages in thread
From: Stephen Hemminger @ 2019-09-12 21:36 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, ranjit.menon, keith.wiles,
	bruce.richardson, antara.ganesh.kolar

On Thu, 12 Sep 2019 10:11:23 -0700
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

> On 9/10/2019 2:19 AM, Stephen Hemminger wrote:
> > On Mon,  9 Sep 2019 12:53:58 -0700
> > Pallavi Kadam <pallavi.kadam@intel.com> wrote:
> >  
> >> --- /dev/null
> >> +++ b/lib/librte_eal/windows/eal/include/getopt.h
> >> @@ -0,0 +1,59 @@
> >> +/* musl as a whole is licensed under the following standard MIT license:
> >> + *
> >> + * ----------------------------------------------------------------------
> >> + * Copyright (c) 2005-2014 Rich Felker, et al.
> >> + *
> >> + * Permission is hereby granted, free of charge, to any person obtaining
> >> + * a copy of this software and associated documentation files (the
> >> + * "Software"), to deal in the Software without restriction, including
> >> + * without limitation the rights to use, copy, modify, merge, publish,
> >> + * distribute, sublicense, and/or sell copies of the Software, and to
> >> + * permit persons to whom the Software is furnished to do so, subject to
> >> + * the following conditions:
> >> + *
> >> + * The above copyright notice and this permission notice shall be
> >> + * included in all copies or substantial portions of the Software.
> >> + *  
> > Although MIT license is similar to BSD license, it is not the same.
> > The DPDK project has converged to only use BSD-3 for all DPDK code (and GPL for kernel code).
> >
> > Please find an alternative that is BSD licensed.  
> 
> We discussed in the Windows Community call regarding the challenges we 
> are facing to find and include
> 
> BSD-3 implementation of getopt and dirent files.
> 
> Please let us know if there can be any exceptions to include MIT license 
> code for Windows
> 
> as mentionedin dpdk.org charter under 6.3 section.
> 
> Thomas, can you please comment on this?
> 

To  get exception needs at least TAB and probably even governing board approval.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-09-12 21:40     ` Stephen Hemminger
  2019-09-13  9:46       ` Bruce Richardson
  0 siblings, 1 reply; 149+ messages in thread
From: Stephen Hemminger @ 2019-09-12 21:40 UTC (permalink / raw)
  To: dev

On Mon,  9 Sep 2019 12:54:01 -0700
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

> Adding getopt_long.c and getopt.c files to support parsing
> option on Windows.
> The original contribution is under MIT license.
> 
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
\ )

Is this the same as BSD?

https://github.com/freebsd/freebsd/blob/master/lib/libc/stdlib/getopt_long.c

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows
  2019-09-12 21:40     ` Stephen Hemminger
@ 2019-09-13  9:46       ` Bruce Richardson
  2019-09-13 17:23         ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Bruce Richardson @ 2019-09-13  9:46 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On Thu, Sep 12, 2019 at 11:40:43PM +0200, Stephen Hemminger wrote:
> On Mon,  9 Sep 2019 12:54:01 -0700
> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
> 
> > Adding getopt_long.c and getopt.c files to support parsing
> > option on Windows.
> > The original contribution is under MIT license.
> > 
> > Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> > Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> > Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> > Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> \ )
> 
> Is this the same as BSD?
> 
> https://github.com/freebsd/freebsd/blob/master/lib/libc/stdlib/getopt_long.c

I'm not sure it matters even if it is. That code is not under a
BSD-3-Clause license either, so still would require the same exceptions.

/Bruce

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows
  2019-09-13  9:46       ` Bruce Richardson
@ 2019-09-13 17:23         ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-13 17:23 UTC (permalink / raw)
  To: Bruce Richardson, Stephen Hemminger; +Cc: dev

Hi Stephen

On 9/13/2019 2:46 AM, Bruce Richardson wrote:
> On Thu, Sep 12, 2019 at 11:40:43PM +0200, Stephen Hemminger wrote:
>> On Mon,  9 Sep 2019 12:54:01 -0700
>> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>>
>>> Adding getopt_long.c and getopt.c files to support parsing
>>> option on Windows.
>>> The original contribution is under MIT license.
>>>
>>> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
>>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>>> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
>> \ )
>>
>> Is this the same as BSD?
>>
>> https://github.com/freebsd/freebsd/blob/master/lib/libc/stdlib/getopt_long.c
> I'm not sure it matters even if it is. That code is not under a
> BSD-3-Clause license either, so still would require the same exceptions.
>
> /Bruce

I don't think these are the same files.

We tried one similar BSD-2-Clause implementation which also builds 
cleanly on Windows.

So, between BSD-2 and MIT License we decided to opt for MIT License 
implementation.

As Bruce mentioned, BSD-2-CLasue implementation is also not acceptable, 
am I correct?


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows
  2019-09-10  9:17     ` Stephen Hemminger
@ 2019-09-25 23:38       ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-25 23:38 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, thomas, Harini.Ramakrishnan, ranjit.menon, keith.wiles,
	bruce.richardson, antara.ganesh.kolar


On 9/10/2019 2:17 AM, Stephen Hemminger wrote:
> On Mon,  9 Sep 2019 12:53:57 -0700
> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
>> +/* Copyright (c) 1982, 1986, 1988, 1993
>> + *	The Regents of the University of California.  All rights reserved.
>> + *
>> + * Redistribution and use in source and binary forms, with or without
>> + * modification, are permitted provided that the following conditions
>> + * are met:
>> + * 1. Redistributions of source code must retain the above copyright
>> + *    notice, this list of conditions and the following disclaimer.
>> + * 2. Redistributions in binary form must reproduce the above copyright
>> + *    notice, this list of conditions and the following disclaimer in the
>> + *    documentation and/or other materials provided with the distribution.
>> + * 4. Neither the name of the University nor the names of its contributors
>> + *    may be used to endorse or promote products derived from this software
>> + *    without specific prior written permission.
>> + *
>> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
>> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> All code must have SPDX license tag and not boiler plate text.
> It should not be merged in current state.

Realized that this file has also adopted SPDX ID tag.

Will replace the boiler plate in v2. Thanks,


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities
  2019-09-09 19:53 ` [dpdk-dev] [PATCH 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                     ` (8 preceding siblings ...)
  2019-09-09 19:54   ` [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2019-09-26 20:29   ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
                       ` (9 more replies)
  9 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and EAL common code
on Windows.

v2 Changes:
 syslog.h: Replaced the BSD license boilerplate to SPDX tag.

Pallavi Kadam (9):
  eal: eal stub to support parsing feature on windows
  eal: syslog implementation for windows
  eal: add windows compatible header files
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/include/rte_lcore.h     |   5 +
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 132 ++++
 lib/librte_eal/windows/eal/getopt_long.c      | 196 ++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 666 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   |  59 ++
 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/rte_vect.h |   9 +
 lib/librte_eal/windows/eal/include/sched.h    |  58 +-
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/include/syslog.h   | 189 +++++
 lib/librte_eal/windows/eal/meson.build        |  10 +-
 16 files changed, 1731 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 1/9] eal: eal stub to support parsing feature on windows
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 2/9] eal: syslog implementation for windows Pallavi Kadam
                       ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding initial stub to support command line parsing
for lcore mask option on Windows.

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/windows/eal/eal.c        | 29 ++++++++++++++++++++++---
 lib/librte_eal/windows/eal/eal_thread.c |  8 +++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..83907ffa6 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -24,6 +24,23 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+}
+
+/* Parse the argument given in the command line of the application */
+static int
+eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+	return 0;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -39,9 +56,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -52,6 +71,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -80,5 +103,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 906502f90..6e5e6f4ab 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -151,3 +151,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 2/9] eal: syslog implementation for windows
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files Pallavi Kadam
                       ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding syslog.h on Windows for supporting common code.
This implementation has BSD-3-Clause licensing.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/syslog.h | 189 ++++++++++++++++++++
 1 file changed, 189 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

diff --git a/lib/librte_eal/windows/eal/include/syslog.h b/lib/librte_eal/windows/eal/include/syslog.h
new file mode 100644
index 000000000..075c0ee48
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/syslog.h
@@ -0,0 +1,189 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ * syslog.h	8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_SYSLOG_H
+#define _SYS_SYSLOG_H 1
+
+#include <stdarg.h>
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number).  Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code.  This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+#define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
+/* extract priority */
+#define	LOG_PRI(p)	((p) & LOG_PRIMASK)
+#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
+
+#ifdef SYSLOG_NAMES
+#define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
+/* mark "facility" */
+#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
+typedef struct _code {
+	char	*c_name;
+	int	c_val;
+} CODE;
+
+CODE prioritynames[] = {
+	{ "alert", LOG_ALERT },
+	{ "crit", LOG_CRIT },
+	{ "debug", LOG_DEBUG },
+	{ "emerg", LOG_EMERG },
+	{ "err", LOG_ERR },
+	{ "error", LOG_ERR },		/* DEPRECATED */
+	{ "info", LOG_INFO },
+	{ "none", INTERNAL_NOPRI },		/* INTERNAL */
+	{ "notice", LOG_NOTICE },
+	{ "panic", LOG_EMERG },		/* DEPRECATED */
+	{ "warn", LOG_WARNING },		/* DEPRECATED */
+	{ "warning", LOG_WARNING },
+	{ NULL, -1 }
+};
+#endif
+
+/* facility codes */
+#define	LOG_KERN	(0<<3)	/* kernel messages */
+#define	LOG_USER	(1<<3)	/* random user-level messages */
+#define	LOG_MAIL	(2<<3)	/* mail system */
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
+#define	LOG_CRON	(9<<3)	/* clock daemon */
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
+
+/* other codes through 15 reserved for system use */
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
+
+#define	LOG_NFACILITIES	24	/* current number of facilities */
+#define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
+/* facility of pri */
+#define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+	{ "auth", LOG_AUTH },
+	{ "authpriv", LOG_AUTHPRIV },
+	{ "cron", LOG_CRON },
+	{ "daemon", LOG_DAEMON },
+	{ "ftp", LOG_FTP },
+	{ "kern", LOG_KERN },
+	{ "lpr", LOG_LPR },
+	{ "mail", LOG_MAIL },
+	{ "mark", INTERNAL_MARK },		/* INTERNAL */
+	{ "news", LOG_NEWS },
+	{ "security", LOG_AUTH },		/* DEPRECATED */
+	{ "syslog", LOG_SYSLOG },
+	{ "user", LOG_USER },
+	{ "uucp", LOG_UUCP },
+	{ "local0", LOG_LOCAL0 },
+	{ "local1", LOG_LOCAL1 },
+	{ "local2", LOG_LOCAL2 },
+	{ "local3", LOG_LOCAL3 },
+	{ "local4", LOG_LOCAL4 },
+	{ "local5", LOG_LOCAL5 },
+	{ "local6", LOG_LOCAL6 },
+	{ "local7", LOG_LOCAL7 },
+	{ NULL, -1 }
+};
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
+#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define	LOG_PID		0x01	/* log the pid with each message */
+#define	LOG_CONS	0x02	/* log on the console if errors in sending */
+#define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
+#define	LOG_NDELAY	0x08	/* don't delay open */
+#define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
+#define	LOG_PERROR	0x20	/* log to stderr as well */
+
+#define SYSLOG_PORT     514
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Close descriptor used to write to system logger.  */
+extern void closelog(void);
+
+/* Open connection to system logger.  */
+extern void openlog(char *__ident, int __option, int __facility);
+
+/* Set the log mask level.  */
+extern int setlogmask(int __mask);
+
+/* Generate a log message using FMT string and option arguments. */
+extern void syslog(int __pri, char *__fmt, ...);
+
+/* Generate a log message using FMT and using arguments pointed to by AP. */
+extern void vsyslog(int __pri, char *__fmt, va_list __ap);
+
+#ifdef _WIN32
+/* Windows specific.
+ *
+ *init_syslog() *must* be called before calling any of the above
+ *functions.  exit_syslog() will be scheduled using atexit().
+ *However, it is not an error and encouraged to call
+ *exit_syslog() before the application exits.
+ *
+ *During operation, the application is free to call exit_syslog()
+ *followed by init_syslog() to re-initialize the library. i.e. if
+ *a different syslog host is to be used.
+ */
+
+/* Initializes the syslog library and sets the syslog host.  The
+ * hostname parameter is of the form "<hostname>[:<port>]".  The
+ * <port> may be a numeric port or it may be a name of a service.
+ * If the <port> is specified using a service name, it will be
+ * looked up using getservbyname().
+ *
+ * On failure, the hostname and port will be set to "localhost"
+ * and SYSLOG_PORT respectively.
+ */
+extern void init_syslog(const char *hostname);
+
+extern void exit_syslog(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* syslog.h */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 2/9] eal: syslog implementation for windows Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-27  7:58       ` Jerin Jacob
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 4/9] eal: dirent.h implementation for windows Pallavi Kadam
                       ` (6 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Adding getopt.h to support parsing options on Windows.

Adding rte_vect.h as Windows fails to compile:
\common\include\arch\x86\rte_vect.h.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dlfcn.h    | 21 ++++
 .../windows/eal/include/eal_filesystem.h      | 99 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   | 59 +++++++++++
 lib/librte_eal/windows/eal/include/rte_vect.h |  9 ++
 4 files changed, 188 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/rte_vect.h

diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..d47202ec9
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,59 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _GETOPT_H
+#define _GETOPT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int getopt(int, char * const [], const char *);
+extern char *optarg;
+extern int optind, opterr, optopt, optreset;
+
+struct option {
+	const char *name;
+	int has_arg;
+	int *flag;
+	int val;
+};
+
+void __getopt_msg(const char *a, const char *b, const char *c, size_t l);
+
+int getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+int getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx);
+
+#define no_argument        0
+#define required_argument  1
+#define optional_argument  2
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
new file mode 100644
index 000000000..630473e28
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/rte_vect.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#pragma once
+
+#define __ICC	1600
+
+#include "..\..\common\include\arch\x86\rte_vect.h"
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 4/9] eal: dirent.h implementation for windows
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (2 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
                       ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding dirent.h on Windows to support common code.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 666 ++++++++++++++++++++
 1 file changed, 666 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..1687e2d85
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,666 @@
+/* Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ *
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * This file is part of dirent.  Dirent may be freely distributed
+ * under the MIT license.  For all details and documentation, see
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (3 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 4/9] eal: dirent.h implementation for windows Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-27  8:06       ` Jerin Jacob
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows Pallavi Kadam
                       ` (4 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

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(-)

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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (4 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 21:27       ` Stephen Hemminger
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 7/9] eal: add function to detect process type Pallavi Kadam
                       ` (3 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding getopt_long.c and getopt.c files to support parsing
option on Windows.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c      | 132 +++++++++++++++
 lib/librte_eal/windows/eal/getopt_long.c | 196 +++++++++++++++++++++++
 lib/librte_eal/windows/eal/meson.build   |   2 +
 3 files changed, 330 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/getopt_long.c

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..760c00eef
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,132 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <wchar.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+char *optarg;
+int optind = 1, opterr = 1, optopt, __optpos, __optreset = 0;
+
+#define optpos __optpos
+
+void
+__getopt_msg(const char *a, const char *b, const char *c, size_t l)
+{
+	FILE *f = stderr;
+	fputs(a, f) >= 0
+	&& fwrite(b, strlen(b), 1, f)
+	&& fwrite(c, 1, l, f) == l
+	&& putc('\n', f);
+}
+
+int
+getopt(int argc, char * const argv[], const char *optstring)
+{
+	int i;
+	wchar_t c, d;
+	int k, l;
+	char *optchar;
+
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+
+	if (optind >= argc || !argv[optind])
+		return -1;
+
+	if (argv[optind][0] != '-') {
+		if (optstring[0] == '-') {
+			optarg = argv[optind++];
+			return 1;
+		}
+		return -1;
+	}
+
+	if (!argv[optind][1])
+		return -1;
+
+	if (argv[optind][1] == '-' && !argv[optind][2])
+		return optind++, -1;
+
+	if (!optpos)
+		optpos++;
+	k = mbtowc(&c, argv[optind] + optpos, MB_LEN_MAX);
+	if (k < 0) {
+		k = 1;
+		c = 0xfffd; /* replacement char */
+	}
+	optchar = argv[optind]+optpos;
+	optpos += k;
+
+	if (!argv[optind][optpos]) {
+		optind++;
+		optpos = 0;
+	}
+
+	if (optstring[0] == '-' || optstring[0] == '+')
+		optstring++;
+
+	i = 0;
+	d = 0;
+	do {
+		l = mbtowc(&d, optstring+i, MB_LEN_MAX);
+		if (l > 0)
+			i += l;
+		else
+			i++;
+	} while (l && d != c);
+
+	if (d != c || c == ':') {
+		optopt = c;
+		if (optstring[0] != ':' && opterr)
+			__getopt_msg(argv[0], ": unrecognized option: ",
+				optchar, k);
+		return '?';
+	}
+	if (optstring[i] == ':') {
+		optarg = 0;
+		if (optstring[i+1] != ':' || optpos) {
+			optarg = argv[optind++] + optpos;
+			optpos = 0;
+		}
+		if (optind > argc) {
+			optopt = c;
+			if (optstring[0] == ':')
+				return ':';
+			if (opterr)
+				__getopt_msg(argv[0],
+				": option requires an argument: ",
+				optchar, k);
+			return '?';
+		}
+	}
+	return c;
+}
diff --git a/lib/librte_eal/windows/eal/getopt_long.c b/lib/librte_eal/windows/eal/getopt_long.c
new file mode 100644
index 000000000..583190783
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt_long.c
@@ -0,0 +1,196 @@
+/* musl as a whole is licensed under the following standard MIT license:
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int __optpos, __optreset;
+
+static void
+permute(char **argv, int dest, int src)
+{
+	char **av = (char **)argv;
+	char *tmp = av[src];
+	int i;
+	for (i = src; i > dest; i--)
+		av[i] = av[i-1];
+	av[dest] = tmp;
+}
+
+static int __getopt_long_core(int argc, char **argv,
+	const char *optstring, const struct option *longopts,
+	int *idx, int longonly);
+
+static int
+__getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	int ret, skipped, resumed;
+	if (!optind || __optreset) {
+		__optreset = 0;
+		__optpos = 0;
+		optind = 1;
+	}
+	if (optind >= argc || !argv[optind])
+		return -1;
+	skipped = optind;
+	if (optstring[0] != '+' && optstring[0] != '-') {
+		int i;
+		for (i = optind; ; i++) {
+			if (i >= argc || !argv[i])
+				return -1;
+			if (argv[i][0] == '-' && argv[i][1])
+				break;
+		}
+		optind = i;
+	}
+	resumed = optind;
+	ret = __getopt_long_core(argc, argv, optstring, longopts,
+		idx, longonly);
+	if (resumed > skipped) {
+		int i, cnt = optind-resumed;
+		for (i = 0; i < cnt; i++)
+			permute(argv, skipped, optind-1);
+		optind = skipped + cnt;
+	}
+	return ret;
+}
+
+static int
+__getopt_long_core(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx, int longonly)
+{
+	optarg = 0;
+	if (longopts && argv[optind][0] == '-' &&
+		((longonly && argv[optind][1] && argv[optind][1] != '-') ||
+		 (argv[optind][1] == '-' && argv[optind][2]))) {
+
+		int colon = optstring[optstring[0] == '+' || optstring[0] ==
+			'-'] == ':';
+		int i, cnt, match;
+		char *arg, *opt, *start = argv[optind]+1;
+		for (cnt = i = 0; longopts[i].name; i++) {
+			const char *name = longopts[i].name;
+			opt = start;
+			if (*opt == '-')
+				opt++;
+			while (*opt && *opt != '=' && *opt == *name)
+				name++, opt++;
+			if (*opt && *opt != '=')
+				continue;
+			arg = opt;
+			match = i;
+			if (!*name) {
+				cnt = 1;
+				break;
+			}
+			cnt++;
+		}
+		if (cnt == 1 && longonly && arg-start ==
+			mblen(start, MB_LEN_MAX)) {
+			int l = arg - start;
+			for (i = 0; optstring[i]; i++) {
+				int j;
+				for (j = 0; j < l && start[j] ==
+					optstring[i + j]; j++)
+					;
+				if (j == l) {
+					cnt++;
+					break;
+				}
+			}
+		}
+		if (cnt == 1) {
+			i = match;
+			opt = arg;
+			optind++;
+			if (*opt == '=') {
+				if (!longopts[i].has_arg) {
+					optopt = longopts[i].val;
+					if (colon || !opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option does not take an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optarg = opt+1;
+			} else if (longopts[i].has_arg == required_argument) {
+				optarg = argv[optind];
+				if (!optarg) {
+					optopt = longopts[i].val;
+					if (colon)
+						return ':';
+					if (!opterr)
+						return '?';
+					__getopt_msg(argv[0],
+						": option requires an argument: ",
+						longopts[i].name,
+						strlen(longopts[i].name));
+					return '?';
+				}
+				optind++;
+			}
+			if (idx)
+				*idx = i;
+			if (longopts[i].flag) {
+				*longopts[i].flag = longopts[i].val;
+				return 0;
+			}
+			return longopts[i].val;
+		}
+		if (argv[optind][1] == '-') {
+			optopt = 0;
+			if (!colon && opterr)
+				__getopt_msg(argv[0], cnt ?
+					": option is ambiguous: " :
+					": unrecognized option: ",
+					argv[optind]+2,
+					strlen(argv[optind]+2));
+			optind++;
+			return '?';
+		}
+	}
+	return getopt(argc, argv, optstring);
+}
+
+int
+getopt_long(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 0);
+}
+
+int
+getopt_long_only(int argc, char **argv, const char *optstring,
+	const struct option *longopts, int *idx)
+{
+	return __getopt_long(argc, argv, optstring, longopts, idx, 1);
+}
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..aa29e2e97 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,6 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
+	'getopt_long.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 7/9] eal: add function to detect process type
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (5 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 8/9] build: add additional common files support Pallavi Kadam
                       ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding a function to detect process type and include
header files to contain suitable function declarations.

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/windows/eal/eal.c        | 51 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_thread.c |  3 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 83907ffa6..ffe5b8552 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,38 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1; // INVALID_HANDLE_VALUE;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +41,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+	eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 6e5e6f4ab..54b9c1dd1 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,10 +10,13 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 8/9] build: add additional common files support
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (6 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 7/9] eal: add function to detect process type Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index aa29e2e97..40c04590f 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v2 9/9] eal: add minimum viable code to support parsing
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (7 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 8/9] build: add additional common files support Pallavi Kadam
@ 2019-09-26 20:29     ` Pallavi Kadam
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 20:29 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson, ranjit.menon,
	antara.ganesh.kolar, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 119 +++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ffe5b8552..8deb6c83a 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -13,8 +13,12 @@
 #include <eal_thread.h>
 #include <eal_internal_cfg.h>
 #include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -73,21 +77,122 @@ enum rte_proc_type_t
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
 /* Parse the arguments for --log-level only */
 static void
-eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+eal_log_level_parse(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
 }
 
 /* Parse the argument given in the command line of the application */
 static int
-eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+eal_parse_args(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
-	return 0;
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
 }
 
 static int
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-09-26 21:27       ` Stephen Hemminger
  2019-09-26 23:26         ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Stephen Hemminger @ 2019-09-26 21:27 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	ranjit.menon, antara.ganesh.kolar

On Thu, 26 Sep 2019 13:29:21 -0700
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

> Adding getopt_long.c and getopt.c files to support parsing
> option on Windows.
> The original contribution is under MIT license.
> 
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>

This would require a licensing exception from the governing board.
And the license should be in LICENSES directory and put a SPDX tag here.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 6/9] eal: getopt implementation for windows
  2019-09-26 21:27       ` Stephen Hemminger
@ 2019-09-26 23:26         ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-26 23:26 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	ranjit.menon, antara.ganesh.kolar

Hi Stephen,

On 9/26/2019 2:27 PM, Stephen Hemminger wrote:
> On Thu, 26 Sep 2019 13:29:21 -0700
> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
>> Adding getopt_long.c and getopt.c files to support parsing
>> option on Windows.
>> The original contribution is under MIT license.
>>
>> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> This would require a licensing exception from the governing board.
> And the license should be in LICENSES directory and put a SPDX tag here.

Planning to include this topic in the upcoming Tech board meeting's agenda.

Hope we can discuss more on receiving an exception for the licensing or 
any other

better solution for such Windows specific files.


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-09-27  7:58       ` Jerin Jacob
  2019-09-30 17:49         ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Jerin Jacob @ 2019-09-27  7:58 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, keith.wiles,
	Richardson, Bruce, ranjit.menon, antara.ganesh.kolar

On Fri, Sep 27, 2019 at 2:24 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
> Adding dlfcn.h on Windows to support common code.
>
> Adding eal_filesystem.h to support functions and
> path defines for files and directories on Windows.
>
> Adding getopt.h to support parsing options on Windows.
>
> Adding rte_vect.h as Windows fails to compile:
> \common\include\arch\x86\rte_vect.h.
>
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
> diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
> new file mode 100644
> index 000000000..630473e28
> --- /dev/null
> +++ b/lib/librte_eal/windows/eal/include/rte_vect.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2019 Intel Corporation
> + */
> +
> +#pragma once
> +
> +#define __ICC  1600
> +
> +#include "..\..\common\include\arch\x86\rte_vect.h"

I understand there is a compilation error with generic rte_vect.h with
windows from the git commit.
But above hardcoding to x86 will create an issue for another arch.
Please fix the compilation
for generic rte_vect.h or introduce vect.h as OS-specific and have
implementation for Linux and FreeBSD.




> --
> 2.18.0.windows.1
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2019-09-27  8:06       ` Jerin Jacob
  2019-09-30 23:11         ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Jerin Jacob @ 2019-09-27  8:06 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, keith.wiles,
	Richardson, Bruce, ranjit.menon, antara.ganesh.kolar

On Fri, Sep 27, 2019 at 2:25 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
> 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(-)
>
> 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)

RTE_CPU* definitions are OS-specific. Instead of adding new #elif and
make the common
code less readable. Please create eal abstraction for the same and
move Linux, FreeBSD, Windows to the specific
directory to avoid #ifdef clutter in lib/librte_eal/common/include/rte_lcore.h.

>  #endif
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files
  2019-09-27  7:58       ` Jerin Jacob
@ 2019-09-30 17:49         ` Pallavi Kadam
  2019-10-01  5:56           ` Jerin Jacob
  0 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-30 17:49 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, keith.wiles,
	Richardson, Bruce, ranjit.menon, antara.ganesh.kolar

Hi Jerin,

On 9/27/2019 12:58 AM, Jerin Jacob wrote:
> On Fri, Sep 27, 2019 at 2:24 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>> Adding dlfcn.h on Windows to support common code.
>>
>> Adding eal_filesystem.h to support functions and
>> path defines for files and directories on Windows.
>>
>> Adding getopt.h to support parsing options on Windows.
>>
>> Adding rte_vect.h as Windows fails to compile:
>> \common\include\arch\x86\rte_vect.h.
>>
>> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
>> ---
>> diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
>> new file mode 100644
>> index 000000000..630473e28
>> --- /dev/null
>> +++ b/lib/librte_eal/windows/eal/include/rte_vect.h
>> @@ -0,0 +1,9 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright(c) 2019 Intel Corporation
>> + */
>> +
>> +#pragma once
>> +
>> +#define __ICC  1600
>> +
>> +#include "..\..\common\include\arch\x86\rte_vect.h"
> I understand there is a compilation error with generic rte_vect.h with
> windows from the git commit.
> But above hardcoding to x86 will create an issue for another arch.
> Please fix the compilation
> for generic rte_vect.h or introduce vect.h as OS-specific and have
> implementation for Linux and FreeBSD.

The error is due to conflict types in the compilers. Clang compiler and 
Windows SDK

both declare _m_prefetchw() in x86intrin.h file which is included from 
generic rte_vect.h.

Error is as below:

C:\Program Files\LLVM\lib\clang\8.0.0\include\prfchwintrin.h:64:1: 
error: conflicting types for '_m_prefetchw'

_m_prefetchw(void *__P)

^

C:\Program Files (x86)\Windows 
Kits\10\include\10.0.17763.0\um\winnt.h:3275:1: note: previous 
declaration is here

_m_prefetchw (

^


Is it ok to include #ifdef for other architectures in the above file itself?

>
>
>
>
>> --
>> 2.18.0.windows.1
>>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 5/9] eal: add additional function overrides in windows header files
  2019-09-27  8:06       ` Jerin Jacob
@ 2019-09-30 23:11         ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-09-30 23:11 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, keith.wiles,
	Richardson, Bruce, ranjit.menon, antara.ganesh.kolar

Hi Jerin,

On 9/27/2019 1:06 AM, Jerin Jacob wrote:
> On Fri, Sep 27, 2019 at 2:25 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>> 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(-)
>>
>> 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)
> RTE_CPU* definitions are OS-specific. Instead of adding new #elif and
> make the common
> code less readable. Please create eal abstraction for the same and
> move Linux, FreeBSD, Windows to the specific
> directory to avoid #ifdef clutter in lib/librte_eal/common/include/rte_lcore.h.

Thanks for the comments.

We have submitted a patch to move RTE_CPU* definitions to the 
OS-specific directory.

Please ACK when possible. https://patches.dpdk.org/patch/60244/.

Thanks,

>
>>   #endif
>>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files
  2019-09-30 17:49         ` Pallavi Kadam
@ 2019-10-01  5:56           ` Jerin Jacob
  2019-10-03  0:40             ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Jerin Jacob @ 2019-10-01  5:56 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, Wiles, Keith,
	Richardson, Bruce, Menon, Ranjit, Kolar, Antara Ganesh

On Mon, Sep 30, 2019 at 11:19 PM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
> Hi Jerin,
>
> On 9/27/2019 12:58 AM, Jerin Jacob wrote:
>
> On Fri, Sep 27, 2019 at 2:24 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
> Adding dlfcn.h on Windows to support common code.
>
> Adding eal_filesystem.h to support functions and
> path defines for files and directories on Windows.
>
> Adding getopt.h to support parsing options on Windows.
>
> Adding rte_vect.h as Windows fails to compile:
> \common\include\arch\x86\rte_vect.h.
>
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
> diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
> new file mode 100644
> index 000000000..630473e28
> --- /dev/null
> +++ b/lib/librte_eal/windows/eal/include/rte_vect.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2019 Intel Corporation
> + */
> +
> +#pragma once
> +
> +#define __ICC  1600
> +
> +#include "..\..\common\include\arch\x86\rte_vect.h"
>
> I understand there is a compilation error with generic rte_vect.h with
> windows from the git commit.
> But above hardcoding to x86 will create an issue for another arch.
> Please fix the compilation
> for generic rte_vect.h or introduce vect.h as OS-specific and have
> implementation for Linux and FreeBSD.
>
> The error is due to conflict types in the compilers. Clang compiler and Windows SDK
>
> both declare _m_prefetchw() in x86intrin.h file which is included from generic rte_vect.h.
>
> Error is as below:
>
> C:\Program Files\LLVM\lib\clang\8.0.0\include\prfchwintrin.h:64:1: error: conflicting types for '_m_prefetchw'
>
> _m_prefetchw(void *__P)
>
> ^
>
> C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winnt.h:3275:1: note: previous declaration is here
>
> _m_prefetchw (
>
> ^
>
>
> Is it ok to include #ifdef for other architectures in the above file itself?


If I understand it correctly, after completing the "make config"
stage, ./lib/librte_eal/common/include/arch/x86/rte_vect.h will be
mapped as build/include/rte_vect.h.
The application will build/include/rte_vect.h and it internally
include ./lib/librte_eal/common/include/generic/rte_vect.h.
If ./lib/librte_eal/common/include/arch/x86/rte_vect.h has compilation
issue, we can have #ifdef fix in arch/x86/rte_vect.h



>
>
>
>
> --
> 2.18.0.windows.1
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/9] eal: add windows compatible header files
  2019-10-01  5:56           ` Jerin Jacob
@ 2019-10-03  0:40             ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-03  0:40 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: dpdk-dev, Thomas Monjalon, Harini.Ramakrishnan, Wiles, Keith,
	Richardson, Bruce, Menon, Ranjit, Kolar, Antara Ganesh


On 9/30/2019 10:56 PM, Jerin Jacob wrote:
> On Mon, Sep 30, 2019 at 11:19 PM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>> Hi Jerin,
>>
>> On 9/27/2019 12:58 AM, Jerin Jacob wrote:
>>
>> On Fri, Sep 27, 2019 at 2:24 AM Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>>
>> Adding dlfcn.h on Windows to support common code.
>>
>> Adding eal_filesystem.h to support functions and
>> path defines for files and directories on Windows.
>>
>> Adding getopt.h to support parsing options on Windows.
>>
>> Adding rte_vect.h as Windows fails to compile:
>> \common\include\arch\x86\rte_vect.h.
>>
>> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
>> ---
>> diff --git a/lib/librte_eal/windows/eal/include/rte_vect.h b/lib/librte_eal/windows/eal/include/rte_vect.h
>> new file mode 100644
>> index 000000000..630473e28
>> --- /dev/null
>> +++ b/lib/librte_eal/windows/eal/include/rte_vect.h
>> @@ -0,0 +1,9 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright(c) 2019 Intel Corporation
>> + */
>> +
>> +#pragma once
>> +
>> +#define __ICC  1600
>> +
>> +#include "..\..\common\include\arch\x86\rte_vect.h"
>>
>> I understand there is a compilation error with generic rte_vect.h with
>> windows from the git commit.
>> But above hardcoding to x86 will create an issue for another arch.
>> Please fix the compilation
>> for generic rte_vect.h or introduce vect.h as OS-specific and have
>> implementation for Linux and FreeBSD.
>>
>> The error is due to conflict types in the compilers. Clang compiler and Windows SDK
>>
>> both declare _m_prefetchw() in x86intrin.h file which is included from generic rte_vect.h.
>>
>> Error is as below:
>>
>> C:\Program Files\LLVM\lib\clang\8.0.0\include\prfchwintrin.h:64:1: error: conflicting types for '_m_prefetchw'
>>
>> _m_prefetchw(void *__P)
>>
>> ^
>>
>> C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winnt.h:3275:1: note: previous declaration is here
>>
>> _m_prefetchw (
>>
>> ^
>>
>>
>> Is it ok to include #ifdef for other architectures in the above file itself?
>
> If I understand it correctly, after completing the "make config"
> stage, ./lib/librte_eal/common/include/arch/x86/rte_vect.h will be
> mapped as build/include/rte_vect.h.
> The application will build/include/rte_vect.h and it internally
> include ./lib/librte_eal/common/include/generic/rte_vect.h.
> If ./lib/librte_eal/common/include/arch/x86/rte_vect.h has compilation
> issue, we can have #ifdef fix in arch/x86/rte_vect.h

Thank you Jerin, for explaining. We have fixed arch/x86/rte_vect.h. Will 
incorporate this change in v3.


>
>
>
>>
>>
>>
>> --
>> 2.18.0.windows.1
>>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities
  2019-09-26 20:29   ` [dpdk-dev] [PATCH v2 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                       ` (8 preceding siblings ...)
  2019-09-26 20:29     ` [dpdk-dev] [PATCH v2 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2019-10-22 20:02     ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
                         ` (9 more replies)
  9 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
        syslog.h: Replaced the BSD license boilerplate to SPDX tag.

Pallavi Kadam (9):
  eal: eal stub to support parsing feature on windows
  eal: syslog implementation for windows
  eal: add windows compatible header files
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  build: add additional common files support
  eal: add minimum viable code to support parsing

 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 498 +++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 668 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   | 150 ++++
 lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
 lib/librte_eal/windows/eal/include/rte_os.h   |  34 +
 lib/librte_eal/windows/eal/include/sched.h    |  58 +-
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/include/syslog.h   | 189 +++++
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 14 files changed, 1988 insertions(+), 12 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 1/9] eal: eal stub to support parsing feature on windows
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 2/9] eal: syslog implementation for windows Pallavi Kadam
                         ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding initial stub to support command line parsing
for lcore mask option on Windows.

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/windows/eal/eal.c        | 29 ++++++++++++++++++++++---
 lib/librte_eal/windows/eal/eal_thread.c |  8 +++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..83907ffa6 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -24,6 +24,23 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+}
+
+/* Parse the argument given in the command line of the application */
+static int
+eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+{
+	/* TODO */
+	/* This is a stub, not the expected result */
+	return 0;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -39,9 +56,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -52,6 +71,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -80,5 +103,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 906502f90..6e5e6f4ab 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -151,3 +151,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 2/9] eal: syslog implementation for windows
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 3/9] eal: add windows compatible header files Pallavi Kadam
                         ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding syslog.h on Windows for supporting common code.
This implementation has BSD-3-Clause licensing.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/syslog.h | 189 ++++++++++++++++++++
 1 file changed, 189 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/syslog.h

diff --git a/lib/librte_eal/windows/eal/include/syslog.h b/lib/librte_eal/windows/eal/include/syslog.h
new file mode 100644
index 000000000..075c0ee48
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/syslog.h
@@ -0,0 +1,189 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ * syslog.h	8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_SYSLOG_H
+#define _SYS_SYSLOG_H 1
+
+#include <stdarg.h>
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number).  Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code.  This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+#define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
+/* extract priority */
+#define	LOG_PRI(p)	((p) & LOG_PRIMASK)
+#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
+
+#ifdef SYSLOG_NAMES
+#define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
+/* mark "facility" */
+#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
+typedef struct _code {
+	char	*c_name;
+	int	c_val;
+} CODE;
+
+CODE prioritynames[] = {
+	{ "alert", LOG_ALERT },
+	{ "crit", LOG_CRIT },
+	{ "debug", LOG_DEBUG },
+	{ "emerg", LOG_EMERG },
+	{ "err", LOG_ERR },
+	{ "error", LOG_ERR },		/* DEPRECATED */
+	{ "info", LOG_INFO },
+	{ "none", INTERNAL_NOPRI },		/* INTERNAL */
+	{ "notice", LOG_NOTICE },
+	{ "panic", LOG_EMERG },		/* DEPRECATED */
+	{ "warn", LOG_WARNING },		/* DEPRECATED */
+	{ "warning", LOG_WARNING },
+	{ NULL, -1 }
+};
+#endif
+
+/* facility codes */
+#define	LOG_KERN	(0<<3)	/* kernel messages */
+#define	LOG_USER	(1<<3)	/* random user-level messages */
+#define	LOG_MAIL	(2<<3)	/* mail system */
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
+#define	LOG_CRON	(9<<3)	/* clock daemon */
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
+
+/* other codes through 15 reserved for system use */
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
+
+#define	LOG_NFACILITIES	24	/* current number of facilities */
+#define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
+/* facility of pri */
+#define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+	{ "auth", LOG_AUTH },
+	{ "authpriv", LOG_AUTHPRIV },
+	{ "cron", LOG_CRON },
+	{ "daemon", LOG_DAEMON },
+	{ "ftp", LOG_FTP },
+	{ "kern", LOG_KERN },
+	{ "lpr", LOG_LPR },
+	{ "mail", LOG_MAIL },
+	{ "mark", INTERNAL_MARK },		/* INTERNAL */
+	{ "news", LOG_NEWS },
+	{ "security", LOG_AUTH },		/* DEPRECATED */
+	{ "syslog", LOG_SYSLOG },
+	{ "user", LOG_USER },
+	{ "uucp", LOG_UUCP },
+	{ "local0", LOG_LOCAL0 },
+	{ "local1", LOG_LOCAL1 },
+	{ "local2", LOG_LOCAL2 },
+	{ "local3", LOG_LOCAL3 },
+	{ "local4", LOG_LOCAL4 },
+	{ "local5", LOG_LOCAL5 },
+	{ "local6", LOG_LOCAL6 },
+	{ "local7", LOG_LOCAL7 },
+	{ NULL, -1 }
+};
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
+#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define	LOG_PID		0x01	/* log the pid with each message */
+#define	LOG_CONS	0x02	/* log on the console if errors in sending */
+#define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
+#define	LOG_NDELAY	0x08	/* don't delay open */
+#define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
+#define	LOG_PERROR	0x20	/* log to stderr as well */
+
+#define SYSLOG_PORT     514
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Close descriptor used to write to system logger.  */
+extern void closelog(void);
+
+/* Open connection to system logger.  */
+extern void openlog(char *__ident, int __option, int __facility);
+
+/* Set the log mask level.  */
+extern int setlogmask(int __mask);
+
+/* Generate a log message using FMT string and option arguments. */
+extern void syslog(int __pri, char *__fmt, ...);
+
+/* Generate a log message using FMT and using arguments pointed to by AP. */
+extern void vsyslog(int __pri, char *__fmt, va_list __ap);
+
+#ifdef _WIN32
+/* Windows specific.
+ *
+ *init_syslog() *must* be called before calling any of the above
+ *functions.  exit_syslog() will be scheduled using atexit().
+ *However, it is not an error and encouraged to call
+ *exit_syslog() before the application exits.
+ *
+ *During operation, the application is free to call exit_syslog()
+ *followed by init_syslog() to re-initialize the library. i.e. if
+ *a different syslog host is to be used.
+ */
+
+/* Initializes the syslog library and sets the syslog host.  The
+ * hostname parameter is of the form "<hostname>[:<port>]".  The
+ * <port> may be a numeric port or it may be a name of a service.
+ * If the <port> is specified using a service name, it will be
+ * looked up using getservbyname().
+ *
+ * On failure, the hostname and port will be set to "localhost"
+ * and SYSLOG_PORT respectively.
+ */
+extern void init_syslog(const char *hostname);
+
+extern void exit_syslog(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* syslog.h */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 3/9] eal: add windows compatible header files
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 1/9] eal: eal stub to support parsing feature on windows Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 2/9] eal: syslog implementation for windows Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 4/9] eal: dirent.h implementation for windows Pallavi Kadam
                         ` (6 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Adding getopt.h to support parsing options on Windows.

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +++
 .../windows/eal/include/eal_filesystem.h      |  99 ++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   | 150 ++++++++++++++++++
 4 files changed, 273 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..2b4887cab
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,150 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+
+/** argument to current option, or NULL if it has none */
+extern char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+#ifndef __CYGWIN__
+#define __progname __argv[0]
+#else
+extern char __declspec(dllimport) * __progname;
+#endif
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+static void
+_vwarnx(const char *fmt, va_list ap)
+{
+	(void)fprintf(stderr, "%s: ", __progname);
+	if (fmt != NULL)
+		(void)vfprintf(stderr, fmt, ap);
+	(void)fprintf(stderr, "\n");
+}
+
+static void
+warnx(const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	_vwarnx(fmt, ap);
+	va_end(ap);
+}
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 4/9] eal: dirent.h implementation for windows
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (2 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
                         ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding dirent.h on Windows to support common code.
The original contribution is under MIT license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 668 ++++++++++++++++++++
 1 file changed, 668 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..2daea1f9b
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,668 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ *
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * This file is part of dirent.  Dirent may be freely distributed
+ * under the MIT license.  For all details and documentation, see
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 5/9] eal: add additional function overrides in windows header files
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (3 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 4/9] eal: dirent.h implementation for windows Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 6/9] eal: getopt implementation for windows Pallavi Kadam
                         ` (4 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

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/windows/eal/include/pthread.h  | 66 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/rte_os.h   | 34 ++++++++++
 lib/librte_eal/windows/eal/include/sched.h    | 58 ++++++++++++++--
 .../windows/eal/include/sys/queue.h           |  8 +++
 4 files changed, 160 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..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..bedd1ab4a 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,28 @@ 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;
+}
+
+/* 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 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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 6/9] eal: getopt implementation for windows
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (4 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 5/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 7/9] eal: add function to detect process type Pallavi Kadam
                         ` (3 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding getopt.c file to support parsing option on
Windows.
The original contribution is under BSD-2 license.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c    | 498 +++++++++++++++++++++++++
 lib/librte_eal/windows/eal/meson.build |   1 +
 2 files changed, 499 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..c6b5427f7
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,498 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <getopt.h>
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+
+char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	char *current_argv, *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	unsigned int buf_count;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, (size_t *)&buf_count, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..60c238e0a 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 7/9] eal: add function to detect process type
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (5 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 6/9] eal: getopt implementation for windows Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 8/9] build: add additional common files support Pallavi Kadam
                         ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding a function to detect process type and include
header files to contain suitable function declarations.

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/windows/eal/eal.c        | 51 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_thread.c |  3 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 83907ffa6..ffe5b8552 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,38 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1; // INVALID_HANDLE_VALUE;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +41,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+	eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 6e5e6f4ab..54b9c1dd1 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,10 +10,13 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 8/9] build: add additional common files support
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (6 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 7/9] eal: add function to detect process type Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index 60c238e0a..460df4383 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v3 9/9] eal: add minimum viable code to support parsing
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (7 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 8/9] build: add additional common files support Pallavi Kadam
@ 2019-10-22 20:02       ` Pallavi Kadam
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2019-10-22 20:02 UTC (permalink / raw)
  To: dev, thomas, Harini.Ramakrishnan
  Cc: keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	ranjit.menon, antara.ganesh.kolar, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 119 +++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ffe5b8552..8deb6c83a 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -13,8 +13,12 @@
 #include <eal_thread.h>
 #include <eal_internal_cfg.h>
 #include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -73,21 +77,122 @@ enum rte_proc_type_t
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
 /* Parse the arguments for --log-level only */
 static void
-eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
+eal_log_level_parse(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
 }
 
 /* Parse the argument given in the command line of the application */
 static int
-eal_parse_args(__rte_unused int argc, __rte_unused char **argv)
+eal_parse_args(int argc, char **argv)
 {
-	/* TODO */
-	/* This is a stub, not the expected result */
-	return 0;
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
 }
 
 static int
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities
  2019-10-22 20:02     ` [dpdk-dev] [PATCH v3 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                         ` (8 preceding siblings ...)
  2019-10-22 20:02       ` [dpdk-dev] [PATCH v3 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-01-09  3:13       ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 1/9] license: add license exception for windows Pallavi Kadam
                           ` (9 more replies)
  9 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and some EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v4 changes:
	Modified license/exceptions.txt file
	The following files in this patch-set require license exceptions as
	listed:
	dirent.h      MIT license
	getopt.h      BSD-2-Clause license
	getopt.c      ISC and BSD-2-Clause license

	Removed syslog file in Windows and added ifndef Windows around syslog
	classification parameters in the common code.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
	syslog.h: Replaced the BSD license boilerplate to SPDX tag.


Pallavi Kadam (9):
  license: add license exception for windows
  eal: dirent.h implementation for windows
  eal: add windows compatible header files
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  eal: remove syslog support for windows
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/eal_common_options.c    |  12 +-
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_debug.c        |   1 +
 lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 465 ++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   | 127 ++++
 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 +
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 license/exceptions.txt                        |  12 +-
 17 files changed, 1764 insertions(+), 21 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 1/9] license: add license exception for windows
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 2/9] eal: dirent.h implementation " Pallavi Kadam
                           ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

The Governing Board and Tech Board have provided exceptions for
MIT and BSD-2-Clause license files for DPDK support on Windows.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 license/exceptions.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/license/exceptions.txt b/license/exceptions.txt
index ee25bb9a1..60b983122 100644
--- a/license/exceptions.txt
+++ b/license/exceptions.txt
@@ -9,9 +9,11 @@ Note that following licenses are not exceptions:-
 	- Dual BSD-3-Clause OR LGPL-2.1
 	- GPL-2.0  (*Only for kernel code*)
 
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
 SPDX Identifier     TB Approval Date  GB Approval Date  File name
------------------------------------------------------------------
-1.
-
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
+1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
+2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
+3.ISC AND
+  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
+---------------------------------------------------------------------------------------------------
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 2/9] eal: dirent.h implementation for windows
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 1/9] license: add license exception for windows Pallavi Kadam
@ 2020-01-09  3:13         ` " Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 3/9] eal: add windows compatible header files Pallavi Kadam
                           ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding dirent.h on Windows to support common code.
eal_common_options.c includes this file.

The original contribution is under MIT license.
https://github.com/tronkko/dirent

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
 1 file changed, 664 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..3a5750788
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,664 @@
+/* SPDX-License-Identifier: MIT
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 3/9] eal: add windows compatible header files
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 1/9] license: add license exception for windows Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 2/9] eal: dirent.h implementation " Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 4/9] eal: add additional function overrides in windows " Pallavi Kadam
                           ` (6 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 .../common/include/arch/x86/rte_vect.h        |  4 +-
 lib/librte_eal/windows/eal/include/dlfcn.h    | 21 ++++
 .../windows/eal/include/eal_filesystem.h      | 99 +++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 4/9] eal: add additional function overrides in windows header files
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (2 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2020-01-09  3:13         ` " Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 5/9] eal: getopt implementation for windows Pallavi Kadam
                           ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 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 <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) \
+	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 <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,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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 5/9] eal: getopt implementation for windows
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (3 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 4/9] eal: add additional function overrides in windows " Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type Pallavi Kadam
                           ` (4 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding getopt files to support parsing option on
Windows.
The original contribution is under BSD-2 license.
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt
.c
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt
.h

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c         | 465 ++++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h | 127 ++++++
 lib/librte_eal/windows/eal/meson.build      |   1 +
 3 files changed, 593 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..34e5313f6
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,465 @@
+/* SPDX-License-Identifier: ISC AND BSD-2-Clause
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+#include <getopt.h>
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+
+const char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	const char *current_argv;
+	char *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	unsigned int buf_count;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, (size_t *)&buf_count, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..722e05381
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+/** argument to current option, or NULL if it has none */
+extern const char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+#ifndef __CYGWIN__
+#define __progname __argv[0]
+#else
+extern char __declspec(dllimport) * __progname;
+#endif
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+static void
+_vwarnx(const char *fmt, va_list ap)
+{
+	(void)fprintf(stderr, "%s: ", __progname);
+	if (fmt != NULL)
+		(void)vfprintf(stderr, "%s", ap);
+	(void)fprintf(stderr, "\n");
+}
+
+static void
+warnx(const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	_vwarnx(fmt, ap);
+	va_end(ap);
+}
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..60c238e0a 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (4 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 5/9] eal: getopt implementation for windows Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  6:35           ` Stephen Hemminger
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 7/9] eal: remove syslog support for windows Pallavi Kadam
                           ` (3 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding a function to detect process type, also included
header files to contain suitable function declarations
and to support extra warning flags.

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/windows/eal/eal.c        | 52 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_debug.c  |  1 +
 lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
 lib/librte_eal/windows/eal/eal_thread.c | 11 ++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..125c0eb47 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,39 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +42,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+	eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c
index edcf257cc..669be6ff9 100644
--- a/lib/librte_eal/windows/eal/eal_debug.c
+++ b/lib/librte_eal/windows/eal/eal_debug.c
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c
index d39f348a3..b3a6c63af 100644
--- a/lib/librte_eal/windows/eal/eal_lcore.c
+++ b/lib/librte_eal/windows/eal/eal_lcore.c
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
 	unsigned int total_procs;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 0591d4c7f..9e4bbaa08 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,11 +10,14 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #include "eal_private.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
@@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 7/9] eal: remove syslog support for windows
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (5 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 8/9] build: add additional common files support Pallavi Kadam
                           ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Added #ifndef WIN64 to exclude syslog definitions and parameters
from Windows builds.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index a7f9c5f9b..3cf32b156 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -6,7 +6,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifndef _WIN64
 #include <syslog.h>
+#endif
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
@@ -204,9 +206,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 		internal_cfg->hugepage_info[i].lock_descriptor = -1;
 	}
 	internal_cfg->base_virtaddr = 0;
-
+#ifndef _WIN64
 	internal_cfg->syslog_facility = LOG_DAEMON;
-
+#endif
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
 
@@ -930,6 +932,7 @@ eal_parse_lcores(const char *lcores)
 	return ret;
 }
 
+#ifndef _WIN64
 static int
 eal_parse_syslog(const char *facility, struct internal_config *conf)
 {
@@ -968,6 +971,7 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 	}
 	return -1;
 }
+#endif
 
 static int
 eal_parse_log_priority(const char *level)
@@ -1391,7 +1395,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
-
+#ifndef _WIN64
 	case OPT_SYSLOG_NUM:
 		if (eal_parse_syslog(optarg, conf) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameters for --"
@@ -1399,7 +1403,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
-
+#endif
 	case OPT_LOG_LEVEL_NUM: {
 		if (eal_parse_log_level(optarg) < 0) {
 			RTE_LOG(ERR, EAL,
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 8/9] build: add additional common files support
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (6 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 7/9] eal: remove syslog support for windows Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index 60c238e0a..460df4383 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v4 9/9] eal: add minimum viable code to support parsing
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (7 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 8/9] build: add additional common files support Pallavi Kadam
@ 2020-01-09  3:13         ` Pallavi Kadam
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09  3:13 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 125c0eb47..5a0583ff7 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -16,6 +16,9 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -74,6 +77,124 @@ enum rte_proc_type_t
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
+/* Parse the argument given in the command line of the application */
+__attribute__((optnone)) static int
+eal_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -89,9 +210,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -102,6 +225,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -130,5 +257,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type Pallavi Kadam
@ 2020-01-09  6:35           ` Stephen Hemminger
  2020-01-09 22:18             ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Stephen Hemminger @ 2020-01-09  6:35 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On Wed,  8 Jan 2020 19:13:09 -0800
Pallavi Kadam <pallavi.kadam@intel.com> wrote:

Minor comments

>  /* Address of global and public configuration */
> -static struct rte_config rte_config;
> +static struct rte_config rte_config = {
> +		.mem_config = &early_mem_config,
> +};

Only single tab is needed for indent here

+enum rte_proc_type_t
+	eal_proc_type_detect(void)

put function in column 1.

enum rte_proc_type_t
eal_proc_type_detect(void)

In a related vain, the existing code fore eal_create_cpu_map does
not follow DPDK coding style at all. It has weird indentation of
for loops and uses C99 style declarations of loop variables.
I guess nobody on Linux side ever looked at the Windows code for that.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v4 6/9] eal: add function to detect process type
  2020-01-09  6:35           ` Stephen Hemminger
@ 2020-01-09 22:18             ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-09 22:18 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar


On 1/8/2020 10:35 PM, Stephen Hemminger wrote:
> On Wed,  8 Jan 2020 19:13:09 -0800
> Pallavi Kadam <pallavi.kadam@intel.com> wrote:
>
> Minor comments
>
>>   /* Address of global and public configuration */
>> -static struct rte_config rte_config;
>> +static struct rte_config rte_config = {
>> +		.mem_config = &early_mem_config,
>> +};
> Only single tab is needed for indent here
>
> +enum rte_proc_type_t
> +	eal_proc_type_detect(void)
>
> put function in column 1.
>
> enum rte_proc_type_t
> eal_proc_type_detect(void)
>
> In a related vain, the existing code fore eal_create_cpu_map does
> not follow DPDK coding style at all. It has weird indentation of
> for loops and uses C99 style declarations of loop variables.
> I guess nobody on Linux side ever looked at the Windows code for that.

Thanks, Stephen.
Will fix this single tab indent in v5.

Also, will send a new patch for eal_create_cpu_map function.
Can you please suggest what exact changes are required here.


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities
  2020-01-09  3:13       ` [dpdk-dev] [PATCH v4 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                           ` (8 preceding siblings ...)
  2020-01-09  3:13         ` [dpdk-dev] [PATCH v4 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-01-13 21:55         ` Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 1/9] license: add license exception for windows Pallavi Kadam
                             ` (9 more replies)
  9 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and some EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v5 changes:
	Fixed indentation in patch 6.

v4 changes:
	Modified license/exceptions.txt file.
	The following files in this patch-set require license exceptions as
	listed:
	dirent.h      MIT license
	getopt.h      BSD-2-Clause license
	getopt.c      ISC and BSD-2-Clause license

	Removed syslog file in Windows and added ifndef Windows around syslog
	classification parameters in the common code.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
	syslog.h: Replaced the BSD license boilerplate to SPDX tag.


Pallavi Kadam (9):
  license: add license exception for windows
  eal: dirent.h implementation for windows
  eal: add windows compatible header files
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  eal: remove syslog support for windows
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/eal_common_options.c    |  12 +-
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_debug.c        |   1 +
 lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 465 ++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/dlfcn.h    |  21 +
 .../windows/eal/include/eal_filesystem.h      |  99 +++
 lib/librte_eal/windows/eal/include/getopt.h   | 127 ++++
 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 +
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 license/exceptions.txt                        |  12 +-
 17 files changed, 1764 insertions(+), 21 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 1/9] license: add license exception for windows
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 2/9] eal: dirent.h implementation " Pallavi Kadam
                             ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

The Governing Board and Tech Board have provided exceptions for
MIT and BSD-2-Clause license files for DPDK support on Windows.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 license/exceptions.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/license/exceptions.txt b/license/exceptions.txt
index ee25bb9a1..60b983122 100644
--- a/license/exceptions.txt
+++ b/license/exceptions.txt
@@ -9,9 +9,11 @@ Note that following licenses are not exceptions:-
 	- Dual BSD-3-Clause OR LGPL-2.1
 	- GPL-2.0  (*Only for kernel code*)
 
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
 SPDX Identifier     TB Approval Date  GB Approval Date  File name
------------------------------------------------------------------
-1.
-
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
+1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
+2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
+3.ISC AND
+  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
+---------------------------------------------------------------------------------------------------
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 2/9] eal: dirent.h implementation for windows
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 1/9] license: add license exception for windows Pallavi Kadam
@ 2020-01-13 21:55           ` " Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files Pallavi Kadam
                             ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding dirent.h on Windows to support common code.
eal_common_options.c includes this file.

The original contribution is under MIT license.
https://github.com/tronkko/dirent

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
 1 file changed, 664 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..3a5750788
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,664 @@
+/* SPDX-License-Identifier: MIT
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 1/9] license: add license exception for windows Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 2/9] eal: dirent.h implementation " Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-27 22:41             ` Thomas Monjalon
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 4/9] eal: add additional function overrides in windows " Pallavi Kadam
                             ` (6 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Adding dlfcn.h on Windows to support common code.

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 .../common/include/arch/x86/rte_vect.h        |  4 +-
 lib/librte_eal/windows/eal/include/dlfcn.h    | 21 ++++
 .../windows/eal/include/eal_filesystem.h      | 99 +++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/windows/eal/include/dlfcn.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
diff --git a/lib/librte_eal/windows/eal/include/dlfcn.h b/lib/librte_eal/windows/eal/include/dlfcn.h
new file mode 100644
index 000000000..1572910b0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dlfcn.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+/**
+ * This file is added to support common code in eal_common_options.c
+ * as Microsoft libc does not contain dlfcn.h. This may be removed
+ * in future releases.
+ */
+
+/* The windows port does not currently support dynamic loading of libraries,
+ * so fail these calls
+ */
+#define dlopen(lib, flag)   (0)
+#define RTLD_NOW 0
+#define dlerror()           ("Not supported!")
+
+#endif /* _DLFCN_H_ */
diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..583617c83
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys
+ */
+int eal_parse_sysfs_value(const char *filename, unsigned long *val);
+
+#endif /* EAL_FILESYSTEM_H */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 4/9] eal: add additional function overrides in windows header files
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (2 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2020-01-13 21:55           ` " Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 5/9] eal: getopt implementation for windows Pallavi Kadam
                             ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 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 <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) \
+	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 <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,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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 5/9] eal: getopt implementation for windows
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (3 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 4/9] eal: add additional function overrides in windows " Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 6/9] eal: add function to detect process type Pallavi Kadam
                             ` (4 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding getopt files to support parsing option on
Windows.

The original contribution is under BSD-2 license.
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.c
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.h

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c         | 465 ++++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h | 127 ++++++
 lib/librte_eal/windows/eal/meson.build      |   1 +
 3 files changed, 593 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..34e5313f6
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,465 @@
+/* SPDX-License-Identifier: ISC AND BSD-2-Clause
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+#include <getopt.h>
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+
+const char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	const char *current_argv;
+	char *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	unsigned int buf_count;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, (size_t *)&buf_count, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..722e05381
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+/** argument to current option, or NULL if it has none */
+extern const char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+#ifndef __CYGWIN__
+#define __progname __argv[0]
+#else
+extern char __declspec(dllimport) * __progname;
+#endif
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+static void
+_vwarnx(const char *fmt, va_list ap)
+{
+	(void)fprintf(stderr, "%s: ", __progname);
+	if (fmt != NULL)
+		(void)vfprintf(stderr, "%s", ap);
+	(void)fprintf(stderr, "\n");
+}
+
+static void
+warnx(const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	_vwarnx(fmt, ap);
+	va_end(ap);
+}
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..60c238e0a 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c'
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 6/9] eal: add function to detect process type
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (4 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 5/9] eal: getopt implementation for windows Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows Pallavi Kadam
                             ` (3 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding a function to detect process type, also included
header files to contain suitable function declarations
and to support extra warning flags.

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/windows/eal/eal.c        | 52 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_debug.c  |  1 +
 lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
 lib/librte_eal/windows/eal/eal_thread.c | 11 ++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..6693c4d60 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,39 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +42,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c
index edcf257cc..669be6ff9 100644
--- a/lib/librte_eal/windows/eal/eal_debug.c
+++ b/lib/librte_eal/windows/eal/eal_debug.c
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c
index d39f348a3..b3a6c63af 100644
--- a/lib/librte_eal/windows/eal/eal_lcore.c
+++ b/lib/librte_eal/windows/eal/eal_lcore.c
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
 	unsigned int total_procs;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 0591d4c7f..9e4bbaa08 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,11 +10,14 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #include "eal_private.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
@@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (5 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 6/9] eal: add function to detect process type Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-27 22:52             ` Thomas Monjalon
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 8/9] build: add additional common files support Pallavi Kadam
                             ` (2 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Added #ifndef WIN64 to exclude syslog definitions and parameters
from Windows builds.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index a7f9c5f9b..3cf32b156 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -6,7 +6,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifndef _WIN64
 #include <syslog.h>
+#endif
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
@@ -204,9 +206,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 		internal_cfg->hugepage_info[i].lock_descriptor = -1;
 	}
 	internal_cfg->base_virtaddr = 0;
-
+#ifndef _WIN64
 	internal_cfg->syslog_facility = LOG_DAEMON;
-
+#endif
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
 
@@ -930,6 +932,7 @@ eal_parse_lcores(const char *lcores)
 	return ret;
 }
 
+#ifndef _WIN64
 static int
 eal_parse_syslog(const char *facility, struct internal_config *conf)
 {
@@ -968,6 +971,7 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 	}
 	return -1;
 }
+#endif
 
 static int
 eal_parse_log_priority(const char *level)
@@ -1391,7 +1395,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
-
+#ifndef _WIN64
 	case OPT_SYSLOG_NUM:
 		if (eal_parse_syslog(optarg, conf) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameters for --"
@@ -1399,7 +1403,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
-
+#endif
 	case OPT_LOG_LEVEL_NUM: {
 		if (eal_parse_log_level(optarg) < 0) {
 			RTE_LOG(ERR, EAL,
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 8/9] build: add additional common files support
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (6 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-27 22:55             ` Thomas Monjalon
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Added support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index 60c238e0a..460df4383 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c'
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v5 9/9] eal: add minimum viable code to support parsing
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (7 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 8/9] build: add additional common files support Pallavi Kadam
@ 2020-01-13 21:55           ` Pallavi Kadam
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-13 21:55 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen, pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 6693c4d60..0d7c45f18 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -16,6 +16,9 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -74,6 +77,124 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
+/* Parse the argument given in the command line of the application */
+__attribute__((optnone)) static int
+eal_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -89,9 +210,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -102,6 +225,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -130,5 +257,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files Pallavi Kadam
@ 2020-01-27 22:41             ` Thomas Monjalon
  2020-01-28 23:34               ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Thomas Monjalon @ 2020-01-27 22:41 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen

13/01/2020 22:55, Pallavi Kadam:
> Modified \common\include\arch\x86\rte_vect.h
> to include SSE4 header for Windows.
> 
> Adding dlfcn.h on Windows to support common code.
> 
> Adding eal_filesystem.h to support functions and
> path defines for files and directories on Windows.

I don't see any relationship between these 3 items,
so I think they should be 3 separate patches.

> --- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
> +++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
> @@ -15,7 +15,9 @@
>  #include <rte_config.h>
>  #include "generic/rte_vect.h"
>  
> -#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
> +#if (defined(__ICC) || \
> +	(defined(_WIN64)) || \
> +	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
>  
>  #include <smmintrin.h> /* SSE4 */

I trust you on this change :)

> --- /dev/null
> +++ b/lib/librte_eal/windows/eal/include/dlfcn.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2019 Intel Corporation
> + */
> +
> +#ifndef _DLFCN_H_
> +#define _DLFCN_H_
> +
> +/**
> + * This file is added to support common code in eal_common_options.c
> + * as Microsoft libc does not contain dlfcn.h. This may be removed
> + * in future releases.
> + */
> +
> +/* The windows port does not currently support dynamic loading of libraries,
> + * so fail these calls
> + */
> +#define dlopen(lib, flag)   (0)
> +#define RTLD_NOW 0
> +#define dlerror()           ("Not supported!")

This is only for the function eal_plugins_init().
The plugin logic and directory search might be different on Windows.
I believe it would be better handled directly in eal_plugins_init().
For now, my advice is to not compile this function (and not call it
in Windows init of course):

int
eal_plugins_init(void)
{
#ifndef RTE_EXEC_ENV_WINDOWS

The right fix would be to move this "common" function in an UNIX-only file:
What about creating eal_unix_options.c file?
Could be in lib/librte_eal/unix/ directory?


> --- /dev/null
> +++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
> @@ -0,0 +1,99 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2019 Intel Corporation
> + */
> +
> +/**
> + * @file
> + * Stores functions and path defines for files and directories
> + * on the filesystem for Windows, that are used by the Windows EAL.
> + */
[...]
> +/** Function to read a single numeric value from a file on the filesystem.
> + * Used to read information from files on /sys
> + */
> +int eal_parse_sysfs_value(const char *filename, unsigned long *val);

Given that sysfs is a Linux system, I guess you don't need this function at all.



^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows Pallavi Kadam
@ 2020-01-27 22:52             ` Thomas Monjalon
  2020-01-28 23:45               ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Thomas Monjalon @ 2020-01-27 22:52 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen

13/01/2020 22:55, Pallavi Kadam:
> Added #ifndef WIN64 to exclude syslog definitions and parameters
> from Windows builds.
> 
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> ---
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -204,9 +206,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
>  		internal_cfg->hugepage_info[i].lock_descriptor = -1;
>  	}
>  	internal_cfg->base_virtaddr = 0;
> -

Please keep blank lines

> +#ifndef _WIN64

Could it be #ifdef LOG_DAEMON?

>  	internal_cfg->syslog_facility = LOG_DAEMON;
> -
> +#endif
[..]
> @@ -1391,7 +1395,7 @@ eal_parse_common_option(int opt, const char *optarg,
> +#ifndef _WIN64
>  	case OPT_SYSLOG_NUM:
>  		if (eal_parse_syslog(optarg, conf) < 0) {

Instead of adding #ifdef, I think we could introduce eal_parse_unix_option()
in a separate file, and it would call eal_parse_common_option().
So in Windows, you just skip it by calling directly eal_parse_common_option()
which would be truly common.




^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 8/9] build: add additional common files support
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 8/9] build: add additional common files support Pallavi Kadam
@ 2020-01-27 22:55             ` Thomas Monjalon
  2020-01-28 23:46               ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Thomas Monjalon @ 2020-01-27 22:55 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen

13/01/2020 22:55, Pallavi Kadam:
> Added support for additional common files in meson build
> to expand Windows EAL and to support the lcore parsing
> feature on Windows.
> 
> 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>
> ---
> --- a/lib/librte_eal/windows/eal/meson.build
> +++ b/lib/librte_eal/windows/eal/meson.build
>  common_sources = files(
> +	'../../common/eal_common_bus.c',
> +	'../../common/eal_common_class.c',
> +	'../../common/eal_common_devargs.c',
>  	'../../common/eal_common_errno.c',
>  	'../../common/eal_common_launch.c',
>  	'../../common/eal_common_lcore.c',
> -	'../../common/eal_common_log.c'
> +	'../../common/eal_common_log.c',
> +	'../../common/eal_common_options.c',
> +	'../../common/eal_common_thread.c',
> +	'../../common/rte_option.c'

Please add a comma after the last item of the list, so the next patch
won't need to change this line.




^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/9] eal: add windows compatible header files
  2020-01-27 22:41             ` Thomas Monjalon
@ 2020-01-28 23:34               ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-28 23:34 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen


On 1/27/2020 2:41 PM, Thomas Monjalon wrote:
> 13/01/2020 22:55, Pallavi Kadam:
>> Modified \common\include\arch\x86\rte_vect.h
>> to include SSE4 header for Windows.
>>
>> Adding dlfcn.h on Windows to support common code.
>>
>> Adding eal_filesystem.h to support functions and
>> path defines for files and directories on Windows.
> I don't see any relationship between these 3 items,
> so I think they should be 3 separate patches.

Ok, will submit 3 separate patches in v6.

>
>> --- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
>> +++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
>> @@ -15,7 +15,9 @@
>>   #include <rte_config.h>
>>   #include "generic/rte_vect.h"
>>   
>> -#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
>> +#if (defined(__ICC) || \
>> +	(defined(_WIN64)) || \
>> +	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
>>   
>>   #include <smmintrin.h> /* SSE4 */
> I trust you on this change :)
>
>> --- /dev/null
>> +++ b/lib/librte_eal/windows/eal/include/dlfcn.h
>> @@ -0,0 +1,21 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright(c) 2019 Intel Corporation
>> + */
>> +
>> +#ifndef _DLFCN_H_
>> +#define _DLFCN_H_
>> +
>> +/**
>> + * This file is added to support common code in eal_common_options.c
>> + * as Microsoft libc does not contain dlfcn.h. This may be removed
>> + * in future releases.
>> + */
>> +
>> +/* The windows port does not currently support dynamic loading of libraries,
>> + * so fail these calls
>> + */
>> +#define dlopen(lib, flag)   (0)
>> +#define RTLD_NOW 0
>> +#define dlerror()           ("Not supported!")
> This is only for the function eal_plugins_init().
> The plugin logic and directory search might be different on Windows.
> I believe it would be better handled directly in eal_plugins_init().
> For now, my advice is to not compile this function (and not call it
> in Windows init of course):
>
> int
> eal_plugins_init(void)
> {
> #ifndef RTE_EXEC_ENV_WINDOWS
>
> The right fix would be to move this "common" function in an UNIX-only file:
> What about creating eal_unix_options.c file?
> Could be in lib/librte_eal/unix/ directory?

Ok. For now will include #ifndef RTE_EXEC_ENV_WINDOWSin v6 and will start working on this new 'unix' directory to add all 
unix based functions.

>
>
>> --- /dev/null
>> +++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
>> @@ -0,0 +1,99 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright(c) 2019 Intel Corporation
>> + */
>> +
>> +/**
>> + * @file
>> + * Stores functions and path defines for files and directories
>> + * on the filesystem for Windows, that are used by the Windows EAL.
>> + */
> [...]
>> +/** Function to read a single numeric value from a file on the filesystem.
>> + * Used to read information from files on /sys
>> + */
>> +int eal_parse_sysfs_value(const char *filename, unsigned long *val);
> Given that sysfs is a Linux system, I guess you don't need this function at all.

Thanks, will remove this function in v6.

>
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 7/9] eal: remove syslog support for windows
  2020-01-27 22:52             ` Thomas Monjalon
@ 2020-01-28 23:45               ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-28 23:45 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen


On 1/27/2020 2:52 PM, Thomas Monjalon wrote:
> 13/01/2020 22:55, Pallavi Kadam:
>> Added #ifndef WIN64 to exclude syslog definitions and parameters
>> from Windows builds.
>>
>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>> ---
>> --- a/lib/librte_eal/common/eal_common_options.c
>> +++ b/lib/librte_eal/common/eal_common_options.c
>> @@ -204,9 +206,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
>>   		internal_cfg->hugepage_info[i].lock_descriptor = -1;
>>   	}
>>   	internal_cfg->base_virtaddr = 0;
>> -
> Please keep blank lines

Sure, will add new lines here.

>
>> +#ifndef _WIN64
> Could it be #ifdef LOG_DAEMON?

Will update this in v6.

>
>>   	internal_cfg->syslog_facility = LOG_DAEMON;
>> -
>> +#endif
> [..]
>> @@ -1391,7 +1395,7 @@ eal_parse_common_option(int opt, const char *optarg,
>> +#ifndef _WIN64
>>   	case OPT_SYSLOG_NUM:
>>   		if (eal_parse_syslog(optarg, conf) < 0) {
> Instead of adding #ifdef, I think we could introduce eal_parse_unix_option()
> in a separate file, and it would call eal_parse_common_option().
> So in Windows, you just skip it by calling directly eal_parse_common_option()
> which would be truly common.

We might have to include changes in multiple files once we create a 'unix' directory
to introduce unix based functions and then test it on Linux and FreeBSD.

For this release, will include #ifndef RTE_EXEC_ENV_WINDOWS for syslog functions
and can add unix based functions in the next release.

>
>
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v5 8/9] build: add additional common files support
  2020-01-27 22:55             ` Thomas Monjalon
@ 2020-01-28 23:46               ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-28 23:46 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	stephen


On 1/27/2020 2:55 PM, Thomas Monjalon wrote:
> 13/01/2020 22:55, Pallavi Kadam:
>> Added support for additional common files in meson build
>> to expand Windows EAL and to support the lcore parsing
>> feature on Windows.
>>
>> 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>
>> ---
>> --- a/lib/librte_eal/windows/eal/meson.build
>> +++ b/lib/librte_eal/windows/eal/meson.build
>>   common_sources = files(
>> +	'../../common/eal_common_bus.c',
>> +	'../../common/eal_common_class.c',
>> +	'../../common/eal_common_devargs.c',
>>   	'../../common/eal_common_errno.c',
>>   	'../../common/eal_common_launch.c',
>>   	'../../common/eal_common_lcore.c',
>> -	'../../common/eal_common_log.c'
>> +	'../../common/eal_common_log.c',
>> +	'../../common/eal_common_options.c',
>> +	'../../common/eal_common_thread.c',
>> +	'../../common/rte_option.c'
> Please add a comma after the last item of the list, so the next patch
> won't need to change this line.

Thanks, will update this in v6.

>
>
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities
  2020-01-13 21:55         ` [dpdk-dev] [PATCH v5 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                             ` (8 preceding siblings ...)
  2020-01-13 21:55           ` [dpdk-dev] [PATCH v5 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-01-31  0:02           ` Pallavi Kadam
  2020-01-31  0:02             ` [dpdk-dev] [PATCH v6 01/10] license: add license exception for windows Pallavi Kadam
                               ` (10 more replies)
  9 siblings, 11 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:02 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and some EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v6 changes:
	Removed sysfs function as it was not required on Windows.
	Removed syslog and dlfcn support for Windows.

v5 changes:
	Fixed indentation in patch 6.

v4 changes:
	Modified license/exceptions.txt file.
	The following files in this patch-set require license exceptions as
	listed:
	dirent.h      MIT license
	getopt.h      BSD-2-Clause license
	getopt.c      ISC and BSD-2-Clause license

	Removed syslog file in Windows and added ifndef Windows around syslog
	classification parameters in the common code.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
	syslog.h: Replaced the BSD license boilerplate to SPDX tag.


Pallavi Kadam (10):
  license: add license exception for windows
  eal: dirent.h implementation for windows
  eal: include filesystem implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  eal: include SSE4 support for windows
  eal: remove syslog and dlfcn support for windows
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/eal_common_options.c    |  12 +
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 185 ++++-
 lib/librte_eal/windows/eal/eal_debug.c        |   1 +
 lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 465 ++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
 .../windows/eal/include/eal_filesystem.h      |  94 +++
 lib/librte_eal/windows/eal/include/getopt.h   | 127 ++++
 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    |  46 ++
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 license/exceptions.txt                        |  12 +-
 16 files changed, 1736 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 01/10] license: add license exception for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2020-01-31  0:02             ` Pallavi Kadam
  2020-01-31  0:02             ` [dpdk-dev] [PATCH v6 02/10] eal: dirent.h implementation " Pallavi Kadam
                               ` (9 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:02 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

The Governing Board and Tech Board have provided exceptions for
MIT and BSD-2-Clause license files for DPDK support on Windows.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 license/exceptions.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/license/exceptions.txt b/license/exceptions.txt
index ee25bb9a1..60b983122 100644
--- a/license/exceptions.txt
+++ b/license/exceptions.txt
@@ -9,9 +9,11 @@ Note that following licenses are not exceptions:-
 	- Dual BSD-3-Clause OR LGPL-2.1
 	- GPL-2.0  (*Only for kernel code*)
 
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
 SPDX Identifier     TB Approval Date  GB Approval Date  File name
------------------------------------------------------------------
-1.
-
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
+1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
+2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
+3.ISC AND
+  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
+---------------------------------------------------------------------------------------------------
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 02/10] eal: dirent.h implementation for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-31  0:02             ` [dpdk-dev] [PATCH v6 01/10] license: add license exception for windows Pallavi Kadam
@ 2020-01-31  0:02             ` " Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 03/10] eal: include filesystem " Pallavi Kadam
                               ` (8 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:02 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding dirent.h on Windows to support common code.
eal_common_options.c includes this file.

The original contribution is under MIT license.
https://github.com/tronkko/dirent

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
 1 file changed, 664 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..3a5750788
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,664 @@
+/* SPDX-License-Identifier: MIT
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 03/10] eal: include filesystem implementation for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-01-31  0:02             ` [dpdk-dev] [PATCH v6 01/10] license: add license exception for windows Pallavi Kadam
  2020-01-31  0:02             ` [dpdk-dev] [PATCH v6 02/10] eal: dirent.h implementation " Pallavi Kadam
@ 2020-01-31  0:03             ` " Pallavi Kadam
  2020-01-31  6:04               ` Dmitry Kozliuk
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 04/10] eal: add additional function overrides in windows header files Pallavi Kadam
                               ` (7 subsequent siblings)
  10 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding eal_filesystem.h to support functions and
path defines for files and directories on Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 .../windows/eal/include/eal_filesystem.h      | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/eal_filesystem.h

diff --git a/lib/librte_eal/windows/eal/include/eal_filesystem.h b/lib/librte_eal/windows/eal/include/eal_filesystem.h
new file mode 100644
index 000000000..0350b0f13
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/eal_filesystem.h
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+/**
+ * @file
+ * Stores functions and path defines for files and directories
+ * on the filesystem for Windows, that are used by the Windows EAL.
+ */
+
+#ifndef EAL_FILESYSTEM_H
+#define EAL_FILESYSTEM_H
+
+#include "eal_internal_cfg.h"
+
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
+/* define the default filename prefix for the %s values below */
+#define HUGEFILE_PREFIX_DEFAULT "rte"
+
+/** Path of rte config file */
+#define RUNTIME_CONFIG_FMT "%s\\%s.config"
+
+static inline const char *
+eal_runtime_config_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	char  Directory[PATH_MAX];
+
+	GetTempPathA(sizeof(Directory), Directory);
+	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
+		internal_config.hugefile_prefix);
+
+	return buffer;
+}
+
+/* Path of file backed array */
+#define FBARRAY_NAME_FMT "%s\\fbarray_%s"
+
+static inline const char *
+eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	return buffer;
+}
+
+/* Path of primary/secondary communication unix socket file. */
+#define MP_SOCKET_FNAME "mp_socket"
+
+static inline const char *
+eal_mp_socket_path(void)
+{
+	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+		MP_SOCKET_FNAME);
+	return buffer;
+}
+
+/** Path of hugepage info file */
+#define HUGEPAGE_INFO_FMT "%s\\.%s_hugepage_info"
+
+static inline const char *
+eal_hugepage_info_path(void)
+{
+	static char buffer[PATH_MAX];  /* static so auto-zeroed */
+	TCHAR  Directory[PATH_MAX];
+
+	GetSystemDirectory(Directory, sizeof(Directory));
+	snprintf(buffer, sizeof(buffer)-1, HUGEPAGE_INFO_FMT, Directory,
+		internal_config.hugefile_prefix);
+	return buffer;
+}
+
+/** String format for hugepage map files */
+#define HUGEFILE_FMT "%s/%smap_%d"
+#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
+
+static inline const char *
+eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir,
+	int f_id)
+{
+	snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
+		internal_config.hugefile_prefix, f_id);
+	buffer[buflen - 1] = '\0';
+	return buffer;
+}
+
+#endif /* EAL_FILESYSTEM_H */
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 04/10] eal: add additional function overrides in windows header files
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (2 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 03/10] eal: include filesystem " Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 05/10] eal: getopt implementation for windows Pallavi Kadam
                               ` (6 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 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    | 46 +++++++++++++
 .../windows/eal/include/sys/queue.h           |  8 +++
 4 files changed, 160 insertions(+)

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 <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) \
+	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 <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,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 29868c93d..fbe07f742 100644
--- a/lib/librte_eal/windows/eal/include/sched.h
+++ b/lib/librte_eal/windows/eal/include/sched.h
@@ -39,6 +39,52 @@ typedef struct _rte_cpuset_s {
 			(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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _i++) \
+		(s)->_bits[_i] = -1LL; \
+} while (0)
+
+#define CPU_NOT(dst, src) \
+do { \
+	unsigned int _i; \
+	for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 05/10] eal: getopt implementation for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (3 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 04/10] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 06/10] eal: add function to detect process type Pallavi Kadam
                               ` (5 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding getopt files to support parsing option on
Windows.

The original contribution is under BSD-2 license.
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.c
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.h

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c         | 465 ++++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h | 127 ++++++
 lib/librte_eal/windows/eal/meson.build      |   1 +
 3 files changed, 593 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..34e5313f6
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,465 @@
+/* SPDX-License-Identifier: ISC AND BSD-2-Clause
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+#include <getopt.h>
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+
+const char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	const char *current_argv;
+	char *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	unsigned int buf_count;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, (size_t *)&buf_count, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..722e05381
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+/** argument to current option, or NULL if it has none */
+extern const char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+#ifndef __CYGWIN__
+#define __progname __argv[0]
+#else
+extern char __declspec(dllimport) * __progname;
+#endif
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+static void
+_vwarnx(const char *fmt, va_list ap)
+{
+	(void)fprintf(stderr, "%s: ", __progname);
+	if (fmt != NULL)
+		(void)vfprintf(stderr, "%s", ap);
+	(void)fprintf(stderr, "\n");
+}
+
+static void
+warnx(const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	_vwarnx(fmt, ap);
+	va_end(ap);
+}
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..d37222158 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 06/10] eal: add function to detect process type
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (4 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 05/10] eal: getopt implementation for windows Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 07/10] eal: include SSE4 support for windows Pallavi Kadam
                               ` (4 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding a function to detect process type, also included
header files to contain suitable function declarations
and to support extra warning flags.

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/windows/eal/eal.c        | 52 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_debug.c  |  1 +
 lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
 lib/librte_eal/windows/eal/eal_thread.c | 11 ++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..6693c4d60 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,39 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +42,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c
index edcf257cc..669be6ff9 100644
--- a/lib/librte_eal/windows/eal/eal_debug.c
+++ b/lib/librte_eal/windows/eal/eal_debug.c
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c
index d39f348a3..b3a6c63af 100644
--- a/lib/librte_eal/windows/eal/eal_lcore.c
+++ b/lib/librte_eal/windows/eal/eal_lcore.c
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
 	unsigned int total_procs;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 0591d4c7f..9e4bbaa08 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,11 +10,14 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #include "eal_private.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
@@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 07/10] eal: include SSE4 support for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (5 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 06/10] eal: add function to detect process type Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 08/10] eal: remove syslog and dlfcn " Pallavi Kadam
                               ` (3 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/common/include/arch/x86/rte_vect.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 08/10] eal: remove syslog and dlfcn support for windows
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (6 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 07/10] eal: include SSE4 support for windows Pallavi Kadam
@ 2020-01-31  0:03             ` " Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 09/10] build: add additional common files support Pallavi Kadam
                               ` (2 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Excluding syslog/ dlfcn definitions and parameters
from Windows by adding #ifndef RTE_EXEC_ENV_WINDOWS.

Note: This is a temporary change. In future, separate
'unix' directory will be created for unix specific functions.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 5920233bc..fc98e6666 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -6,12 +6,16 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
+#endif
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
@@ -205,7 +209,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	}
 	internal_cfg->base_virtaddr = 0;
 
+#ifdef LOG_DAEMON
 	internal_cfg->syslog_facility = LOG_DAEMON;
+#endif
 
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
@@ -278,6 +284,7 @@ eal_plugindir_init(const char *path)
 int
 eal_plugins_init(void)
 {
+#ifndef RTE_EXEC_ENV_WINDOWS
 	struct shared_driver *solib = NULL;
 	struct stat sb;
 
@@ -306,6 +313,7 @@ eal_plugins_init(void)
 
 	}
 	return 0;
+#endif
 }
 
 /*
@@ -927,6 +935,7 @@ eal_parse_lcores(const char *lcores)
 	return ret;
 }
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 static int
 eal_parse_syslog(const char *facility, struct internal_config *conf)
 {
@@ -965,6 +974,7 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 	}
 	return -1;
 }
+#endif
 
 static int
 eal_parse_log_priority(const char *level)
@@ -1389,6 +1399,7 @@ eal_parse_common_option(int opt, const char *optarg,
 		}
 		break;
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 	case OPT_SYSLOG_NUM:
 		if (eal_parse_syslog(optarg, conf) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameters for --"
@@ -1396,6 +1407,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
+#endif
 
 	case OPT_LOG_LEVEL_NUM: {
 		if (eal_parse_log_level(optarg) < 0) {
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 09/10] build: add additional common files support
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (7 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 08/10] eal: remove syslog and dlfcn " Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 10/10] eal: add minimum viable code to support parsing Pallavi Kadam
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Added support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index d37222158..2a062c365 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c',
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v6 10/10] eal: add minimum viable code to support parsing
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (8 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 09/10] build: add additional common files support Pallavi Kadam
@ 2020-01-31  0:03             ` Pallavi Kadam
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  10 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 6693c4d60..0d7c45f18 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -16,6 +16,9 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -74,6 +77,124 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
+/* Parse the argument given in the command line of the application */
+__attribute__((optnone)) static int
+eal_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -89,9 +210,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -102,6 +225,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -130,5 +257,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v6 03/10] eal: include filesystem implementation for windows
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 03/10] eal: include filesystem " Pallavi Kadam
@ 2020-01-31  6:04               ` Dmitry Kozliuk
  2020-01-31 22:03                 ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Dmitry Kozliuk @ 2020-01-31  6:04 UTC (permalink / raw)
  To: dev

Hello Pallavi,

> +#include "eal_internal_cfg.h"
> +
> +/* sets up platform-specific runtime data dir */
> +int
> +eal_create_runtime_dir(void);
> +
> +/* returns runtime dir */
> +const char *
> +eal_get_runtime_dir(void);

Any reason not to #include "eal_filesystem.h"?

> +
> +static inline const char *
> +eal_runtime_config_path(void)
> +{
> +	static char buffer[PATH_MAX];  /* static so auto-zeroed */
> +	char  Directory[PATH_MAX];

Should be "directory" according to the style guide.

> +
> +	GetTempPathA(sizeof(Directory), Directory);
> +	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,

Style guide requires spaces around binary "-".

> +static inline const char *
> +eal_hugepage_info_path(void)
> +{
> +	static char buffer[PATH_MAX];  /* static so auto-zeroed */
> +	TCHAR  Directory[PATH_MAX];

Should be "directory", see above.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v6 03/10] eal: include filesystem implementation for windows
  2020-01-31  6:04               ` Dmitry Kozliuk
@ 2020-01-31 22:03                 ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-01-31 22:03 UTC (permalink / raw)
  To: Dmitry Kozliuk, dev

Hi Dmitry,

Thank you for reviewing the code and for your comments.

On 1/30/2020 10:04 PM, Dmitry Kozliuk wrote:
> Hello Pallavi,
>
>> +#include "eal_internal_cfg.h"
>> +
>> +/* sets up platform-specific runtime data dir */
>> +int
>> +eal_create_runtime_dir(void);
>> +
>> +/* returns runtime dir */
>> +const char *
>> +eal_get_runtime_dir(void);
> Any reason not to #include "eal_filesystem.h"?

Do you mean, we can exclude "eal_filesystem.h" in the current patchset?
If so, you are correct. This file was required before to include
eal_runtime_config_path() when compiling with VS/ ICC, I think.
But, now 'common' version of eal_filesystem.h can be used for Windows.
For other function definitions, we can always #include "eal_filesystem.h"
if require later.

>
>> +
>> +static inline const char *
>> +eal_runtime_config_path(void)
>> +{
>> +	static char buffer[PATH_MAX];  /* static so auto-zeroed */
>> +	char  Directory[PATH_MAX];
> Should be "directory" according to the style guide.

Thanks, will be sending out new version and excluding this file
as mentioned above.

>
>> +
>> +	GetTempPathA(sizeof(Directory), Directory);
>> +	snprintf(buffer, sizeof(buffer)-1, RUNTIME_CONFIG_FMT, Directory,
> Style guide requires spaces around binary "-".
>
>> +static inline const char *
>> +eal_hugepage_info_path(void)
>> +{
>> +	static char buffer[PATH_MAX];  /* static so auto-zeroed */
>> +	TCHAR  Directory[PATH_MAX];
> Should be "directory", see above.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities
  2020-01-31  0:02           ` [dpdk-dev] [PATCH v6 00/10] Windows patchset with additional EAL functionalities Pallavi Kadam
                               ` (9 preceding siblings ...)
  2020-01-31  0:03             ` [dpdk-dev] [PATCH v6 10/10] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-02-01  0:03             ` Pallavi Kadam
  2020-02-01  0:03               ` [dpdk-dev] [PATCH v7 1/9] license: add license exception for windows Pallavi Kadam
                                 ` (9 more replies)
  10 siblings, 10 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and some EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v7 changes:
	Removed Windows "eal_filesystem.h" for now and will be added
	later if required. Currently, Windows EAL uses common version
	of eal_filesystem.h.

v6 changes:
	Removed sysfs function as it was not required on Windows.
	Removed syslog and dlfcn support for Windows.

v5 changes:
	Fixed indentation in patch 6.

v4 changes:
	Modified license/exceptions.txt file.
	The following files in this patch-set require license exceptions as
	listed:
	dirent.h      MIT license
	getopt.h      BSD-2-Clause license
	getopt.c      ISC and BSD-2-Clause license

	Removed syslog file in Windows and added ifndef Windows around syslog
	classification parameters in the common code.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
	syslog.h: Replaced the BSD license boilerplate to SPDX tag.


Pallavi Kadam (9):
  license: add license exception for windows
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  eal: include SSE4 support for windows
  eal: remove syslog and dlfcn support for windows
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/eal_common_options.c    |  12 +
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 194 ++++-
 lib/librte_eal/windows/eal/eal_debug.c        |   1 +
 lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 465 ++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   | 127 ++++
 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    |  46 ++
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 license/exceptions.txt                        |  12 +-
 15 files changed, 1651 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 1/9] license: add license exception for windows
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2020-02-01  0:03               ` Pallavi Kadam
  2020-02-01  0:03               ` [dpdk-dev] [PATCH v7 2/9] eal: dirent.h implementation " Pallavi Kadam
                                 ` (8 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

The Governing Board and Tech Board have provided exceptions for
MIT and BSD-2-Clause license files for DPDK support on Windows.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 license/exceptions.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/license/exceptions.txt b/license/exceptions.txt
index ee25bb9a1..60b983122 100644
--- a/license/exceptions.txt
+++ b/license/exceptions.txt
@@ -9,9 +9,11 @@ Note that following licenses are not exceptions:-
 	- Dual BSD-3-Clause OR LGPL-2.1
 	- GPL-2.0  (*Only for kernel code*)
 
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
 SPDX Identifier     TB Approval Date  GB Approval Date  File name
------------------------------------------------------------------
-1.
-
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
+1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
+2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
+3.ISC AND
+  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
+---------------------------------------------------------------------------------------------------
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 2/9] eal: dirent.h implementation for windows
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-02-01  0:03               ` [dpdk-dev] [PATCH v7 1/9] license: add license exception for windows Pallavi Kadam
@ 2020-02-01  0:03               ` " Pallavi Kadam
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
                                 ` (7 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:03 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding dirent.h on Windows to support common code.
eal_common_options.c includes this file.

The original contribution is under MIT license.
https://github.com/tronkko/dirent

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
 1 file changed, 664 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..3a5750788
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,664 @@
+/* SPDX-License-Identifier: MIT
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 3/9] eal: add additional function overrides in windows header files
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-02-01  0:03               ` [dpdk-dev] [PATCH v7 1/9] license: add license exception for windows Pallavi Kadam
  2020-02-01  0:03               ` [dpdk-dev] [PATCH v7 2/9] eal: dirent.h implementation " Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-05 19:54                 ` Dmitry Kozlyuk
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 4/9] eal: getopt implementation for windows Pallavi Kadam
                                 ` (6 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 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    | 46 +++++++++++++
 .../windows/eal/include/sys/queue.h           |  8 +++
 4 files changed, 160 insertions(+)

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 <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) \
+	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 <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,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 29868c93d..fbe07f742 100644
--- a/lib/librte_eal/windows/eal/include/sched.h
+++ b/lib/librte_eal/windows/eal/include/sched.h
@@ -39,6 +39,52 @@ typedef struct _rte_cpuset_s {
 			(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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _i++) \
+		(s)->_bits[_i] = -1LL; \
+} while (0)
+
+#define CPU_NOT(dst, src) \
+do { \
+	unsigned int _i; \
+	for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 4/9] eal: getopt implementation for windows
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (2 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type Pallavi Kadam
                                 ` (5 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding getopt files to support parsing option on
Windows.

The original contribution is under BSD-2 license.
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.c
https://raw.githubusercontent.com/greenplum-db/libusual/master/usual/getopt.h

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c         | 465 ++++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h | 127 ++++++
 lib/librte_eal/windows/eal/meson.build      |   1 +
 3 files changed, 593 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..34e5313f6
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,465 @@
+/* SPDX-License-Identifier: ISC AND BSD-2-Clause
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+#include <getopt.h>
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+
+const char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	const char *current_argv;
+	char *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	unsigned int buf_count;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, (size_t *)&buf_count, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..722e05381
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+/** argument to current option, or NULL if it has none */
+extern const char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+#ifndef __CYGWIN__
+#define __progname __argv[0]
+#else
+extern char __declspec(dllimport) * __progname;
+#endif
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+static void
+_vwarnx(const char *fmt, va_list ap)
+{
+	(void)fprintf(stderr, "%s: ", __progname);
+	if (fmt != NULL)
+		(void)vfprintf(stderr, "%s", ap);
+	(void)fprintf(stderr, "\n");
+}
+
+static void
+warnx(const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	_vwarnx(fmt, ap);
+	va_end(ap);
+}
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..d37222158 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (3 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 4/9] eal: getopt implementation for windows Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-05 20:04                 ` Dmitry Kozlyuk
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 6/9] eal: include SSE4 support for windows Pallavi Kadam
                                 ` (4 subsequent siblings)
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding a function to detect process type, also included
header files to contain suitable function declarations
and to support extra warning flags.

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/windows/eal/eal.c        | 61 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_debug.c  |  1 +
 lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
 lib/librte_eal/windows/eal/eal_thread.c | 11 +++++
 4 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..931a5860c 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,48 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+const char *
+rte_eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +51,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED sOverlapped = { 0 };
+		sOverlapped.Offset = sizeof(*rte_config.mem_config);
+		sOverlapped.OffsetHigh = 0;
+
+		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hWinFileHandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &sOverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c
index edcf257cc..669be6ff9 100644
--- a/lib/librte_eal/windows/eal/eal_debug.c
+++ b/lib/librte_eal/windows/eal/eal_debug.c
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c
index d39f348a3..b3a6c63af 100644
--- a/lib/librte_eal/windows/eal/eal_lcore.c
+++ b/lib/librte_eal/windows/eal/eal_lcore.c
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
 	unsigned int total_procs;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 0591d4c7f..9e4bbaa08 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,11 +10,14 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #include "eal_private.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
@@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 6/9] eal: include SSE4 support for windows
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (4 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 7/9] eal: remove syslog and dlfcn " Pallavi Kadam
                                 ` (3 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/common/include/arch/x86/rte_vect.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 7/9] eal: remove syslog and dlfcn support for windows
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (5 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 6/9] eal: include SSE4 support for windows Pallavi Kadam
@ 2020-02-01  0:04               ` " Pallavi Kadam
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 8/9] build: add additional common files support Pallavi Kadam
                                 ` (2 subsequent siblings)
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Excluding syslog/ dlfcn definitions and parameters
from Windows by adding #ifndef RTE_EXEC_ENV_WINDOWS.

Note: This is a temporary change. In future, separate
'unix' directory will be created for unix specific functions.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 5920233bc..fc98e6666 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -6,12 +6,16 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
+#endif
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
@@ -205,7 +209,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	}
 	internal_cfg->base_virtaddr = 0;
 
+#ifdef LOG_DAEMON
 	internal_cfg->syslog_facility = LOG_DAEMON;
+#endif
 
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
@@ -278,6 +284,7 @@ eal_plugindir_init(const char *path)
 int
 eal_plugins_init(void)
 {
+#ifndef RTE_EXEC_ENV_WINDOWS
 	struct shared_driver *solib = NULL;
 	struct stat sb;
 
@@ -306,6 +313,7 @@ eal_plugins_init(void)
 
 	}
 	return 0;
+#endif
 }
 
 /*
@@ -927,6 +935,7 @@ eal_parse_lcores(const char *lcores)
 	return ret;
 }
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 static int
 eal_parse_syslog(const char *facility, struct internal_config *conf)
 {
@@ -965,6 +974,7 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 	}
 	return -1;
 }
+#endif
 
 static int
 eal_parse_log_priority(const char *level)
@@ -1389,6 +1399,7 @@ eal_parse_common_option(int opt, const char *optarg,
 		}
 		break;
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 	case OPT_SYSLOG_NUM:
 		if (eal_parse_syslog(optarg, conf) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameters for --"
@@ -1396,6 +1407,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
+#endif
 
 	case OPT_LOG_LEVEL_NUM: {
 		if (eal_parse_log_level(optarg) < 0) {
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 8/9] build: add additional common files support
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (6 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 7/9] eal: remove syslog and dlfcn " Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Added support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index d37222158..2a062c365 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c',
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (7 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 8/9] build: add additional common files support Pallavi Kadam
@ 2020-02-01  0:04               ` Pallavi Kadam
  2020-02-05 19:54                 ` Dmitry Kozlyuk
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  9 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-01  0:04 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 931a5860c..6a4778954 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -16,6 +16,9 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -83,6 +86,124 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
+/* Parse the argument given in the command line of the application */
+__attribute__((optnone)) static int
+eal_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -98,9 +219,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -111,6 +234,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -139,5 +266,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-02-05 19:54                 ` Dmitry Kozlyuk
  2020-02-06  0:39                   ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-05 19:54 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

[-- Attachment #1: Type: text/plain, Size: 70 bytes --]

Crashes at argument parsing, WinDbg log attached.

-- 
Dmitry Kozlyuk

[-- Attachment #2: windbg.txt --]
[-- Type: text/plain, Size: 3594 bytes --]

Microsoft (R) Windows Debugger Version 10.0.18362.1 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: build\native\clang\examples\dpdk-helloworld.exe -cf --log-level=eal:8
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00007ff6`76480000 00007ff6`7653d000   dpdk-helloworld.exe
ModLoad: 00007ffb`4a720000 00007ffb`4a910000   ntdll.dll
ModLoad: 00007ffb`49470000 00007ffb`49522000   C:\Windows\System32\KERNEL32.DLL
ModLoad: 00007ffb`47800000 00007ffb`47aa3000   C:\Windows\System32\KERNELBASE.dll
(143c.1ed8): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ffb`4a7f11dc cc              int     3
0:000> g
Critical error detected c0000374
(143c.1ed8): Break instruction exception - code 80000003 (first chance)
ntdll!RtlReportCriticalFailure+0x56:
00007ffb`4a8191f2 cc              int     3
0:000> kb
 # RetAddr           : Args to Child                                                           : Call Site
00 00007ffb`4a821622 : 00000000`00000000 00007ffb`4a8827f0 00000000`00000009 00000205`68c10000 : ntdll!RtlReportCriticalFailure+0x56
01 00007ffb`4a82192a : 00000000`00000009 00000205`68c10000 00000205`68c10000 00007ff6`7648a6b7 : ntdll!RtlpHeapHandleError+0x12
02 00007ffb`4a82a8e9 : 00000205`68c10000 ffffffff`ffffffff 00000001`00000000 00000003`00000002 : ntdll!RtlpHpHeapHandleError+0x7a
03 00007ffb`4a7607df : ffffffff`ffffffff ffffffff`ffffffff ffffffff`ffffffff ffffffff`ffffffff : ntdll!RtlpLogHeapFailure+0x45
04 00007ffb`4a75fc11 : ffffffff`ffffffff 00000205`68c10000 00000000`00000000 00000000`00000000 : ntdll!RtlpFreeHeapInternal+0x75f
*** WARNING: Unable to verify checksum for dpdk-helloworld.exe
05 00007ff6`764df8ac : 00000205`68c16cf0 00000000`00000000 ffffffff`ffffffff ffffffff`ffffffff : ntdll!RtlFreeHeap+0x51
06 00007ff6`76493c97 : ffffffff`ffffffff ffffffff`00000000 ffffffff`ffffffff ffffffff`ffffffff : dpdk_helloworld!_free_base+0x1c [minkernel\crts\ucrt\src\appcrt\heap\free_base.cpp @ 105] 
07 00007ff6`764944de : ffffffff`ffffffff ffffffff`ffffffff ffffffff`ffffffff ffffffff`ffffffff : dpdk_helloworld!getopt_internal+0x117 [Z:\lib\librte_eal\windows\eal\getopt.c @ 264] 
08 00007ff6`76487efa : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : dpdk_helloworld!usual_getopt_long+0x5e [Z:\lib\librte_eal\windows\eal\getopt.c @ 448] 
09 00007ff6`76487be4 : 00007ff6`76507110 00000000`00000022 00000000`00000004 00000000`00000200 : dpdk_helloworld!eal_parse_args+0x4a [Z:\lib\librte_eal\windows\eal\eal.c @ 148] 
0a 00007ff6`76487493 : 02040800`000506e3 1f8bfbff`fffa3223 0000001d`76507790 00007ff6`7649bc61 : dpdk_helloworld!rte_eal_init+0x74 [Z:\lib\librte_eal\windows\eal\eal.c @ 237] 
0b 00007ff6`7649b5fc : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : dpdk_helloworld!main+0x23 [Z:\examples\helloworld\main.c @ 33] 
0c (Inline Function) : --------`-------- --------`-------- --------`-------- --------`-------- : dpdk_helloworld!invoke_main+0x22 [d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 78] 
0d 00007ffb`49487bd4 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : dpdk_helloworld!__scrt_common_main_seh+0x10c [d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
0e 00007ffb`4a78ced1 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
0f 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 3/9] eal: add additional function overrides in windows header files
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2020-02-05 19:54                 ` Dmitry Kozlyuk
  0 siblings, 0 replies; 149+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-05 19:54 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

> +#include <Windows.h>

Nit: better use lowercase to support cross-compilation from OS with
case-sensitive FS. It's not directly relevant for this patch. 

> +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;
> +}

Shouldn't EAL implementation follow DPDK code style? If so, "threadID" and
"dwPrevAffinityMask" violate naming convention, also there's a bogus TAB.

> +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);
> +}

Duplicates eal_thread_create() from "eal_thread.c", probably
eal_thread_create() should call pthread_create() as in Linux EAL.

> +static inline int
> +pthread_join(pthread_t thread __attribute__((__unused__)),
> +	void **value_ptr __attribute__((__unused__)))
> +{
> +	return 0;
> +}

If not implemented, should return EINVAL (ENOSUP is not listed as a valid
error code for this function). Even better, implement trivially with
WaitForSingleObject().


> +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);

Missing a check for NULL from malloc().

> +
> +	va_start(arg, format);
> +	ret = vsnprintf(*buffer, size, format, arg);
> +	va_end(arg);
> +	if (ret != size - 1) {
> +		free(*buffer);
> +		return -1;
> +	}
> +	return ret;
> +}

> +static inline int
> +count_cpu(rte_cpuset_t *s)
> +{
> +	unsigned int _i;

Why the underscore? It's not a macro, identifiers are function-local.

> +/*
> + * 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

Probably ouf of scope for this patchset, but DPDK should probably include
the entire FreeBSD <sys/queue.h> so that we won't need to add it
piece-by-piece like so. It's BSD-3-Clause anyway.

-- 
Dmitry Kozlyuk

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type Pallavi Kadam
@ 2020-02-05 20:04                 ` Dmitry Kozlyuk
  2020-02-06  0:56                   ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-05 20:04 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

> +/* Detect if we are a primary or a secondary process */
> +enum rte_proc_type_t
> +eal_proc_type_detect(void)
> +{
[...]
> +		OVERLAPPED sOverlapped = { 0 };
> +		sOverlapped.Offset = sizeof(*rte_config.mem_config);
> +		sOverlapped.OffsetHigh = 0;
> +
> +		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
[...]

Identifiers don't follow naming conventions.

-- 
Dmitry Kozlyuk

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-05 19:54                 ` Dmitry Kozlyuk
@ 2020-02-06  0:39                   ` Pallavi Kadam
  2020-02-06  1:39                     ` Pallavi Kadam
  0 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-06  0:39 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar


On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:
> Crashes at argument parsing, WinDbg log attached.

This patch works fine with meson=0.49.
I was able to execute the 'helloworld' app.

When I tried to build with meson=0.52 it failed with the error:
[9/25] Linking target lib/librte_kvargs-20.0.dll.
FAILED: lib/librte_kvargs-20.0.dll
clang @lib/librte_kvargs-20.0.dll.rsp
clang: error: no such file or directory: '/OPT:REF'

Not completely sure, if this could be the reason for the crash.

>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type
  2020-02-05 20:04                 ` Dmitry Kozlyuk
@ 2020-02-06  0:56                   ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-06  0:56 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar


On 2/5/2020 12:04 PM, Dmitry Kozlyuk wrote:
>> +/* Detect if we are a primary or a secondary process */
>> +enum rte_proc_type_t
>> +eal_proc_type_detect(void)
>> +{
> [...]
>> +		OVERLAPPED sOverlapped = { 0 };
>> +		sOverlapped.Offset = sizeof(*rte_config.mem_config);
>> +		sOverlapped.OffsetHigh = 0;
>> +
>> +		HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
> [...]
>
> Identifiers don't follow naming conventions.

Thank you, will fix this in v8.

>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  0:39                   ` Pallavi Kadam
@ 2020-02-06  1:39                     ` Pallavi Kadam
  2020-02-06  2:11                       ` Thomas Monjalon
  2020-02-06  6:41                       ` Dmitry Kozlyuk
  0 siblings, 2 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-06  1:39 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar


On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
>
>
> On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:
>> Crashes at argument parsing, WinDbg log attached.
> This patch works fine with meson=0.49.
> I was able to execute the 'helloworld' app.
>
> When I tried to build with meson=0.52 it failed with the error:
> [9/25] Linking target lib/librte_kvargs-20.0.dll.
> FAILED: lib/librte_kvargs-20.0.dll
> clang @lib/librte_kvargs-20.0.dll.rsp
> clang: error: no such file or directory: '/OPT:REF'

Fixed this error with the patch you sent before.
were able to execute parsing:

$ ./build/examples/dpdk-helloworld.exe -l 4-8
EAL: Detected 20 lcore(s)
EAL: Detected 2 NUMA nodes
hello from core 5
hello from core 6
hello from core 7
hello from core 8
hello from core 4

>
> Not completely sure, if this could be the reason for the crash.

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  1:39                     ` Pallavi Kadam
@ 2020-02-06  2:11                       ` Thomas Monjalon
  2020-02-06  3:18                         ` Pallavi Kadam
  2020-02-06  6:41                       ` Dmitry Kozlyuk
  1 sibling, 1 reply; 149+ messages in thread
From: Thomas Monjalon @ 2020-02-06  2:11 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: Dmitry Kozlyuk, dev, Harini.Ramakrishnan, keith.wiles,
	bruce.richardson, david.marchand, jerinjacobk, ranjit.menon,
	antara.ganesh.kolar

06/02/2020 02:39, Pallavi Kadam:
> On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
> > On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:
> >> Crashes at argument parsing, WinDbg log attached.
> > This patch works fine with meson=0.49.
> > I was able to execute the 'helloworld' app.
> >
> > When I tried to build with meson=0.52 it failed with the error:
> > [9/25] Linking target lib/librte_kvargs-20.0.dll.
> > FAILED: lib/librte_kvargs-20.0.dll
> > clang @lib/librte_kvargs-20.0.dll.rsp
> > clang: error: no such file or directory: '/OPT:REF'
> 
> Fixed this error with the patch you sent before.

Which patch?
Please ack the patch so I can merge it.




^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  2:11                       ` Thomas Monjalon
@ 2020-02-06  3:18                         ` Pallavi Kadam
  0 siblings, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-06  3:18 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Dmitry Kozlyuk, dev, Harini.Ramakrishnan, keith.wiles,
	bruce.richardson, david.marchand, jerinjacobk, ranjit.menon,
	antara.ganesh.kolar


On 2/5/2020 6:11 PM, Thomas Monjalon wrote:
> 06/02/2020 02:39, Pallavi Kadam:
>> On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
>>> On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:
>>>> Crashes at argument parsing, WinDbg log attached.
>>> This patch works fine with meson=0.49.
>>> I was able to execute the 'helloworld' app.
>>>
>>> When I tried to build with meson=0.52 it failed with the error:
>>> [9/25] Linking target lib/librte_kvargs-20.0.dll.
>>> FAILED: lib/librte_kvargs-20.0.dll
>>> clang @lib/librte_kvargs-20.0.dll.rsp
>>> clang: error: no such file or directory: '/OPT:REF'
>> Fixed this error with the patch you sent before.
> Which patch?
> Please ack the patch so I can merge it.

The patch below fixes the meson error:
clang: error: no such file or directory: '/OPT:REF'

https://github.com/mesonbuild/meson/pull/6483 @Dmitry, Can you please 
confirm if you can still see the crash?

>
>
>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  1:39                     ` Pallavi Kadam
  2020-02-06  2:11                       ` Thomas Monjalon
@ 2020-02-06  6:41                       ` Dmitry Kozlyuk
  2020-02-06  9:26                         ` Thomas Monjalon
  2020-02-07  3:45                         ` [dpdk-dev] " Pallavi Kadam
  1 sibling, 2 replies; 149+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:41 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]



> On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
> >
> >
> > On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:  
> >> Crashes at argument parsing, WinDbg log attached.  
> > This patch works fine with meson=0.49.
> > I was able to execute the 'helloworld' app.
> >
> > When I tried to build with meson=0.52 it failed with the error:
> > [9/25] Linking target lib/librte_kvargs-20.0.dll.
> > FAILED: lib/librte_kvargs-20.0.dll
> > clang @lib/librte_kvargs-20.0.dll.rsp
> > clang: error: no such file or directory: '/OPT:REF'  
> 
> Fixed this error with the patch you sent before.
> were able to execute parsing:
> 
> $ ./build/examples/dpdk-helloworld.exe -l 4-8
> EAL: Detected 20 lcore(s)
> EAL: Detected 2 NUMA nodes
> hello from core 5
> hello from core 6
> hello from core 7
> hello from core 8
> hello from core 4
> 
> >
> > Not completely sure, if this could be the reason for the crash.  

The crash does not happen with any arguments, "-l 4-8" works fine as do
"-cf" and "-v", but "--log-level=eal:8" crashes reproducibly. I assume
application should not crash on invalid options, but report an error and exit.
For the reference, I applied your patchset to the latest dpdk:master.

Z:\>build\native\clang\examples\dpdk-helloworld.exe
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes

	OK, no lcores specified.

Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes
hello from core 1
hello from core 2
hello from core 3
hello from core 0

	OK, 4 lcores enabled.

Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf --log-level=eal:8

	Crash, WinDbg log attached to bug report.

Z:\>echo %errorlevel%
-1073741819

Z:\>

Attaching the build log, but I don't think it matters, it's something with
getopt implementation or it's use, judging by stack trace.

P.S. I can also see "--syslog" option in the help message, you should
probably hide it via #ifndef, as you did with said option handling.

-- 
Dmitry Kozlyuk

[-- Attachment #2: clang.txt --]
[-- Type: text/plain, Size: 7649 bytes --]

Z:\>ninja -C build\native\clang
ninja: Entering directory `build\native\clang'
[0/1] Regenerating build files.
The Meson build system
Version: 0.53.999
Source dir: \\10.0.2.4\qemu
Build dir: \\10.0.2.4\qemu\build\native\clang
Build type: native build
Program cat found: NO
Program more found: YES (C:\Windows\system32\more.COM)
Project name: DPDK
Project version: 20.02.0-rc1
C compiler for the host machine: clang (clang 9.0.1 "clang version 9.0.1 ")
C linker for the host machine: clang link 14.24.28316.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program cat found: NO
Program more found: YES (C:\Windows\system32\more.COM)
Program ../buildtools/symlink-drivers-solibs.sh found: YES (sh \\10.0.2.4\qemu\config\../buildtools/symlink-drivers-solibs.sh)
Checking for size of "void *" : 8
Library m found: NO
Library numa found: NO
Did not find pkg-config by name 'pkg-config'
Found Pkg-config: NO
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libbsd found: NO (tried pkgconfig and cmake)
pcap-config found: NO
Run-time dependency pcap found: NO (tried pkgconfig and config-tool)
Compiler for C supports arguments -Wextra: YES (cached)
config\meson.build:202: WARNING: Consider using the built-in warning_level option instead of using "-Wextra".
Compiler for C supports arguments -Wcast-qual: YES (cached)
Compiler for C supports arguments -Wdeprecated: YES (cached)
Compiler for C supports arguments -Wformat-nonliteral: YES (cached)
Compiler for C supports arguments -Wformat-security: YES (cached)
Compiler for C supports arguments -Wmissing-declarations: YES (cached)
Compiler for C supports arguments -Wmissing-prototypes: YES (cached)
Compiler for C supports arguments -Wnested-externs: YES (cached)
Compiler for C supports arguments -Wold-style-definition: YES (cached)
Compiler for C supports arguments -Wpointer-arith: YES (cached)
Compiler for C supports arguments -Wsign-compare: YES (cached)
Compiler for C supports arguments -Wstrict-prototypes: YES (cached)
Compiler for C supports arguments -Wundef: YES (cached)
Compiler for C supports arguments -Wwrite-strings: YES (cached)
Compiler for C supports arguments -Wno-address-of-packed-member: YES (cached)
Compiler for C supports arguments -Wno-packed-not-aligned: NO (cached)
Compiler for C supports arguments -Wno-missing-field-initializers: YES (cached)
Fetching value of define "__SSE4_2__" : 1 (cached)
Fetching value of define "__AES__" : 1 (cached)
Fetching value of define "__PCLMUL__" : 1 (cached)
Fetching value of define "__AVX__" : 1 (cached)
Fetching value of define "__AVX2__" : 1 (cached)
Fetching value of define "__AVX512F__" :  (cached)
Fetching value of define "__RDRND__" : 1 (cached)
Fetching value of define "__RDSEED__" : 1 (cached)
Program gen-pmdinfo-cfile.sh found: YES (sh \\10.0.2.4\qemu\buildtools\gen-pmdinfo-cfile.sh)
Program check-experimental-syms.sh found: YES (sh \\10.0.2.4\qemu\buildtools\check-experimental-syms.sh)
Program python3 found: YES (C:\Python\python.exe)
Program grep found: NO
Program findstr found: YES (C:\Windows\system32\findstr.EXE)
Compiler for C supports arguments -Wno-format-truncation: NO (cached)
Message: lib/librte_kvargs: Defining dependency "kvargs"
Checking for function "getentropy" : NO (cached)
Message: lib/librte_eal: Defining dependency "eal"
Program doxygen found: NO
Program sphinx-build found: NO
Library execinfo found: NO
Compiler for C supports arguments -Wno-format-truncation: NO (cached)
Configuring rte_build_config.h using configuration
Message:
=================
Libraries Enabled
=================

libs:
        kvargs, eal,

Message:
===============
Drivers Enabled
===============


Message:
=================
Content Skipped
=================

libs:

drivers:


Build targets in project: 8

Found ninja.EXE-1.9.0 at "C:\Program Files\Meson\ninja.EXE"
[8/25] Compiling C object lib/76b5a35@@rte_eal@sta/librte_eal_common_rte_option.c.obj.
In file included from ../../../lib/librte_eal/common/rte_option.c:5:
..\..\..\lib/librte_eal/windows/eal/include\getopt.h:117:1: warning: unused function 'warnx' [-Wunused-function]
warnx(const char *fmt, ...)
^
1 warning generated.
[9/25] Linking target lib/librte_kvargs-0.200.dll.
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
LINK : warning LNK4044: unrecognized option '/-no-as-needed'; ignored
   Creating library lib\librte_kvargs.dll.a and object lib\librte_kvargs.dll.exp
[15/25] Compiling C object lib/76b5a35@@rte_eal@sta/librte_eal_windows_eal_eal.c.obj.
In file included from ../../../lib/librte_eal/windows/eal/eal.c:16:
In file included from ..\..\..\lib\librte_eal\common\eal_options.h:8:
..\..\..\lib/librte_eal/windows/eal/include\getopt.h:117:1: warning: unused function 'warnx' [-Wunused-function]
warnx(const char *fmt, ...)
^
1 warning generated.
[16/25] Compiling C object lib/76b5a35@@rte_eal@sta/librte_eal_common_eal_common_thread.c.obj.
../../../lib/librte_eal/common/eal_common_thread.c:170:25: warning: unused parameter 'attr' [-Wunused-parameter]
                const pthread_attr_t *attr,
                                      ^
1 warning generated.
[17/25] Compiling C object lib/76b5a35@@rte_eal@sta/librte_eal_common_eal_common_options.c.obj.
../../../lib/librte_eal/common/eal_common_options.c:263:10: warning: 'strerror' is deprecated: This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
                        path, strerror(errno));
                              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h:181:16: note: 'strerror' has been explicitly marked deprecated here
_Check_return_ _CRT_INSECURE_DEPRECATE(strerror_s)
               ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:311:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
        #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
                                                      ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:301:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
                                              ^
../../../lib/librte_eal/common/eal_common_options.c:317:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
In file included from ../../../lib/librte_eal/common/eal_common_options.c:15:
..\..\..\lib/librte_eal/windows/eal/include\getopt.h:117:1: warning: unused function 'warnx' [-Wunused-function]
warnx(const char *fmt, ...)
^
../../../lib/librte_eal/common/eal_common_options.c:107:20: warning: unused variable 'default_solib_dir' [-Wunused-variable]
static const char *default_solib_dir = RTE_EAL_PMD_PATH;
                   ^
../../../lib/librte_eal/common/eal_common_options.c:251:1: warning: unused function 'eal_plugindir_init' [-Wunused-function]
eal_plugindir_init(const char *path)
^
5 warnings generated.
[24/25] Linking target examples/dpdk-helloworld.exe.
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
LINK : warning LNK4044: unrecognized option '/-no-as-needed'; ignored
[25/25] Linking target lib/librte_eal-0.200.dll.
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
LINK : warning LNK4044: unrecognized option '/-no-as-needed'; ignored
   Creating library lib\librte_eal.dll.a and object lib\librte_eal.dll.exp

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  6:41                       ` Dmitry Kozlyuk
@ 2020-02-06  9:26                         ` Thomas Monjalon
  2020-02-07 16:46                           ` Ranjit Menon
  2020-02-08  0:43                           ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:45                         ` [dpdk-dev] " Pallavi Kadam
  1 sibling, 2 replies; 149+ messages in thread
From: Thomas Monjalon @ 2020-02-06  9:26 UTC (permalink / raw)
  To: Pallavi Kadam, Dmitry Kozlyuk, Harini.Ramakrishnan, ranjit.menon
  Cc: dev, keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	antara.ganesh.kolar

As discussed in community meeting, the goal was to have core parsing
in Windows EAL 20.02.
Given that there is a crash and a doubt on the imported getopt library,
I think it's better to postpone this series to 20.05.


06/02/2020 07:41, Dmitry Kozlyuk:
> > On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
> > > On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:  
> > >> Crashes at argument parsing, WinDbg log attached.  
> > > This patch works fine with meson=0.49.
> > > I was able to execute the 'helloworld' app.
> > >
> > > When I tried to build with meson=0.52 it failed with the error:
> > > [9/25] Linking target lib/librte_kvargs-20.0.dll.
> > > FAILED: lib/librte_kvargs-20.0.dll
> > > clang @lib/librte_kvargs-20.0.dll.rsp
> > > clang: error: no such file or directory: '/OPT:REF'  
> > 
> > Fixed this error with the patch you sent before.
> > were able to execute parsing:
> > 
> > $ ./build/examples/dpdk-helloworld.exe -l 4-8
> > EAL: Detected 20 lcore(s)
> > EAL: Detected 2 NUMA nodes
> > hello from core 5
> > hello from core 6
> > hello from core 7
> > hello from core 8
> > hello from core 4
> > 
> > >
> > > Not completely sure, if this could be the reason for the crash.  
> 
> The crash does not happen with any arguments, "-l 4-8" works fine as do
> "-cf" and "-v", but "--log-level=eal:8" crashes reproducibly. I assume
> application should not crash on invalid options, but report an error and exit.
> For the reference, I applied your patchset to the latest dpdk:master.
> 
> Z:\>build\native\clang\examples\dpdk-helloworld.exe
> EAL: Detected 4 lcore(s)
> EAL: Detected 1 NUMA nodes
> 
> 	OK, no lcores specified.
> 
> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf
> EAL: Detected 4 lcore(s)
> EAL: Detected 1 NUMA nodes
> hello from core 1
> hello from core 2
> hello from core 3
> hello from core 0
> 
> 	OK, 4 lcores enabled.
> 
> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf --log-level=eal:8
> 
> 	Crash, WinDbg log attached to bug report.
> 
> Z:\>echo %errorlevel%
> -1073741819
> 
> Z:\>
> 
> Attaching the build log, but I don't think it matters, it's something with
> getopt implementation or it's use, judging by stack trace.
> 
> P.S. I can also see "--syslog" option in the help message, you should
> probably hide it via #ifndef, as you did with said option handling.






^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-01  0:03             ` [dpdk-dev] [PATCH v7 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                 ` (8 preceding siblings ...)
  2020-02-01  0:04               ` [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-02-07  3:14               ` Pallavi Kadam
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows Pallavi Kadam
                                   ` (14 more replies)
  9 siblings, 15 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

This patchset includes additional functionalities for Windows EAL
to support command-line parsing feature and some EAL common code
on Windows.

This patchset can be applied to windpdk-next-dev branch in the draft repo.

v8 changes:
	Fixed the naming conventions.
	Fixed a crash encountered due to getopt function.
	Removed "--syslog" from help options for Windows.

v7 changes:
	Removed Windows "eal_filesystem.h" for now and will be added
	later if required. Currently, Windows EAL uses common version
	of eal_filesystem.h.

v6 changes:
	Removed sysfs function as it was not required on Windows.
	Removed syslog and dlfcn support for Windows.

v5 changes:
	Fixed indentation in patch 6.

v4 changes:
	Modified license/exceptions.txt file.
	The following files in this patch-set require license exceptions as
	listed:
	dirent.h      MIT license
	getopt.h      BSD-2-Clause license
	getopt.c      ISC and BSD-2-Clause license

	Removed syslog file in Windows and added ifndef Windows around syslog
	classification parameters in the common code.

v3 Changes:
 	Modified generic rte_vect to add Windows support.
	Moved RTE_CPU* definitions to OS specific file.
	Added SPDX tag on top of third party files.

v2 Changes:
	syslog.h: Replaced the BSD license boilerplate to SPDX tag.


Pallavi Kadam (9):
  license: add license exception for windows
  eal: dirent.h implementation for windows
  eal: add additional function overrides in windows header files
  eal: getopt implementation for windows
  eal: add function to detect process type
  eal: include SSE4 support for windows
  eal: remove syslog and dlfcn support for windows
  build: add additional common files support
  eal: add minimum viable code to support parsing

 lib/librte_eal/common/eal_common_options.c    |  14 +
 .../common/include/arch/x86/rte_vect.h        |   4 +-
 lib/librte_eal/windows/eal/eal.c              | 194 ++++-
 lib/librte_eal/windows/eal/eal_debug.c        |   1 +
 lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
 lib/librte_eal/windows/eal/eal_thread.c       |  11 +
 lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
 lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
 lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
 lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
 lib/librte_eal/windows/eal/include/sched.h    |  46 ++
 .../windows/eal/include/sys/queue.h           |   8 +
 lib/librte_eal/windows/eal/meson.build        |   9 +-
 license/exceptions.txt                        |  12 +-
 15 files changed, 1625 insertions(+), 11 deletions(-)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:38                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-12 21:38                   ` [dpdk-dev] " Thomas Monjalon
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 2/9] eal: dirent.h implementation " Pallavi Kadam
                                   ` (13 subsequent siblings)
  14 siblings, 2 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

The Governing Board and Tech Board have provided exceptions for
MIT and BSD-2-Clause license files for DPDK support on Windows.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 license/exceptions.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/license/exceptions.txt b/license/exceptions.txt
index ee25bb9a1..60b983122 100644
--- a/license/exceptions.txt
+++ b/license/exceptions.txt
@@ -9,9 +9,11 @@ Note that following licenses are not exceptions:-
 	- Dual BSD-3-Clause OR LGPL-2.1
 	- GPL-2.0  (*Only for kernel code*)
 
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
 SPDX Identifier     TB Approval Date  GB Approval Date  File name
------------------------------------------------------------------
-1.
-
------------------------------------------------------------------
+---------------------------------------------------------------------------------------------------
+1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
+2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
+3.ISC AND
+  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
+---------------------------------------------------------------------------------------------------
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 2/9] eal: dirent.h implementation for windows
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows Pallavi Kadam
@ 2020-02-07  3:14                 ` " Pallavi Kadam
  2020-02-12  0:40                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
                                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding dirent.h on Windows to support common code.
eal_common_options.c includes this file.

The original contribution is under MIT license.
https://github.com/tronkko/dirent

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
 1 file changed, 664 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

diff --git a/lib/librte_eal/windows/eal/include/dirent.h b/lib/librte_eal/windows/eal/include/dirent.h
new file mode 100644
index 000000000..3a5750788
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/dirent.h
@@ -0,0 +1,664 @@
+/* SPDX-License-Identifier: MIT
+ * Dirent interface for Microsoft Visual Studio
+ * Version 1.21
+ * Copyright (C) 2006-2012 Toni Ronkko
+ * https://github.com/tronkko/dirent
+ */
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+/*
+ * Include windows.h without Windows Sockets 1.1 to prevent conflicts with
+ * Windows Sockets 2.0.
+ */
+#ifndef WIN32_LEAN_AND_MEAN
+#   define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Maximum length of file name */
+#if !defined(PATH_MAX)
+#   define PATH_MAX MAX_PATH
+#endif
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_CHR S_IFCHR
+
+/*
+ * File type macros.  Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility.  These macros should always return false
+ * on Windows.
+ */
+#if !defined(S_ISDIR)
+#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if !defined(S_ISREG)
+#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+/* Wide-character version */
+struct _wdirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	wchar_t d_name[PATH_MAX];
+};
+typedef struct _wdirent _wdirent;
+
+struct _WDIR {
+	/* Current directory entry */
+	struct _wdirent ent;
+
+	/* Private file data */
+	WIN32_FIND_DATAW data;
+
+	/* True if data is valid */
+	int cached;
+
+	/* Win32 search handle */
+	HANDLE handle;
+
+	/* Initial directory name */
+	wchar_t *patt;
+};
+typedef struct _WDIR _WDIR;
+
+static _WDIR *_wopendir(const wchar_t *dirname);
+static int _wclosedir(_WDIR *dirp);
+
+/* For compatibility with Symbian */
+#define wdirent _wdirent
+#define WDIR _WDIR
+#define wopendir _wopendir
+#define wclosedir _wclosedir
+
+/* Multi-byte character versions */
+struct dirent {
+	/* Always zero */
+	long d_ino;
+
+	/* Structure size */
+	unsigned short d_reclen;
+
+	/* Length of name without \0 */
+	size_t d_namlen;
+
+	/* File type */
+	int d_type;
+
+	/* File name */
+	char d_name[PATH_MAX];
+};
+typedef struct dirent dirent;
+
+struct DIR {
+	struct dirent ent;
+	struct _WDIR *wdirp;
+};
+typedef struct DIR DIR;
+
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+
+/* Internal utility functions */
+static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
+static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
+
+static int dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count);
+
+static int dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes,
+	const wchar_t *wcstr,
+	size_t count);
+
+static void dirent_set_errno(int error);
+
+/*
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static _WDIR*
+_wopendir(const wchar_t *dirname)
+{
+	_WDIR *dirp = NULL;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate new _WDIR structure */
+	dirp = (_WDIR *)malloc(sizeof(struct _WDIR));
+	if (dirp != NULL) {
+		DWORD n;
+
+		/* Reset _WDIR structure */
+		dirp->handle = INVALID_HANDLE_VALUE;
+		dirp->patt = NULL;
+		dirp->cached = 0;
+
+		/* Compute the length of full path plus zero terminator
+		 *
+		 * Note that on WinRT there's no way to convert relative paths
+		 * into absolute paths, so just assume its an absolute path.
+		 */
+	#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+		n = wcslen(dirname);
+	#else
+		n = GetFullPathNameW(dirname, 0, NULL, NULL);
+	#endif
+
+		/* Allocate room for absolute directory name and search
+		 * pattern
+		 */
+		dirp->patt = (wchar_t *)malloc(sizeof(wchar_t) * n + 16);
+		if (dirp->patt) {
+			/* Convert relative directory name to an
+			 * absolute one. This allows rewinddir() to
+			 * function correctly even when  current working
+			 * directory is changed between opendir()
+			 * and rewinddir().
+			 *
+			 * Note that on WinRT there's no way to convert
+			 * relative paths into absolute paths, so just
+			 * assume its an absolute path.
+			 */
+			#if defined(WINAPI_FAMILY) &&                   \
+				(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+			wcsncpy_s(dirp->patt, n + 1, dirname, n);
+			#else
+			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
+			#endif
+			if (n > 0) {
+				wchar_t *p;
+
+				/* Append search pattern \* to the directory
+				 * name
+				 */
+				p = dirp->patt + n;
+				if (dirp->patt < p) {
+					switch (p[-1]) {
+					case '\\':
+					case '/':
+					case ':':
+					/* Directory ends in path separator,
+					 * e.g.c:\temp\
+					 */
+						/*NOP*/;
+						break;
+
+					default:
+					/* Directory name doesn't end in path
+					 * separator
+					 */
+						*p++ = '\\';
+					}
+				}
+				*p++ = '*';
+				*p = '\0';
+
+				/* Open directory stream and retrieve the first
+				 * entry
+				 */
+				if (dirent_first(dirp)) {
+				/* Directory stream opened successfully */
+					error = 0;
+				} else {
+					/* Cannot retrieve first entry */
+					error = 1;
+					dirent_set_errno(ENOENT);
+				}
+
+			} else {
+				/* Cannot retrieve full path name */
+				dirent_set_errno(ENOENT);
+				error = 1;
+			}
+
+		} else {
+			/* Cannot allocate memory for search pattern */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate _WDIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		_wclosedir(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Close directory stream opened by opendir() function.
+ * This invalidates the DIR structure as well as any directory
+ * entry read previously by _wreaddir().
+ */
+static int
+_wclosedir(_WDIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Release search handle */
+		if (dirp->handle != INVALID_HANDLE_VALUE) {
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+		}
+
+		/* Release search pattern */
+		if (dirp->patt) {
+			free(dirp->patt);
+			dirp->patt = NULL;
+		}
+
+		/* Release directory structure */
+		free(dirp);
+		ok = /*success*/0;
+
+	} else {
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+	}
+	return ok;
+}
+
+/* Get first directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_first(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+
+	/* Open directory and retrieve the first entry */
+	dirp->handle = FindFirstFileExW(
+		dirp->patt, FindExInfoStandard, &dirp->data,
+		FindExSearchNameMatch, NULL, 0);
+	if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* a directory entry is now waiting in memory */
+		datap = &dirp->data;
+		dirp->cached = 1;
+
+	} else {
+
+		/* Failed to re-open directory: no directory entry in memory */
+		dirp->cached = 0;
+		datap = NULL;
+
+	}
+	return datap;
+}
+
+/* Get next directory entry (internal) */
+static WIN32_FIND_DATAW*
+dirent_next(_WDIR *dirp)
+{
+	WIN32_FIND_DATAW *p;
+
+	/* Get next directory entry */
+	if (dirp->cached != 0) {
+
+		/* A valid directory entry already in memory */
+		p = &dirp->data;
+		dirp->cached = 0;
+
+	} else if (dirp->handle != INVALID_HANDLE_VALUE) {
+
+		/* Get the next directory entry from stream */
+		if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
+			/* Got a file */
+			p = &dirp->data;
+		} else {
+			/* The very last entry has been processed
+			 *or an error occurred
+			 */
+			FindClose(dirp->handle);
+			dirp->handle = INVALID_HANDLE_VALUE;
+			p = NULL;
+		}
+
+	} else {
+
+		/* End of directory stream reached */
+		p = NULL;
+
+	}
+
+	return p;
+}
+
+/*
+ * Open directory stream using plain old C-string.
+ */
+static DIR*
+opendir(const char *dirname)
+{
+	struct DIR *dirp;
+	int error;
+
+	/* Must have directory name */
+	if (dirname == NULL || dirname[0] == '\0') {
+		dirent_set_errno(ENOENT);
+		return NULL;
+	}
+
+	/* Allocate memory for DIR structure */
+	dirp = (DIR *)malloc(sizeof(struct DIR));
+	if (dirp) {
+		wchar_t wname[PATH_MAX];
+		size_t n;
+
+		/* Convert directory name to wide-character string */
+		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
+			dirname, PATH_MAX);
+		if (!error) {
+
+			/* Open directory stream using wide-character name */
+			dirp->wdirp = _wopendir(wname);
+			if (dirp->wdirp) {
+				/* Directory stream opened */
+				error = 0;
+			} else {
+				/* Failed to open directory stream */
+				error = 1;
+			}
+
+		} else {
+			/*
+			 * Cannot convert file name to wide-character string.
+			 * This occurs if the string contains invalid multi-byte
+			 * sequences or the output buffer is too small to
+			 * contain the resulting string.
+			 */
+			error = 1;
+		}
+
+	} else {
+		/* Cannot allocate DIR structure */
+		error = 1;
+	}
+
+	/* Clean up in case of error */
+	if (error  &&  dirp) {
+		free(dirp);
+		dirp = NULL;
+	}
+
+	return dirp;
+}
+
+/*
+ * Read next directory entry.
+ *
+ * When working with text consoles, please note that file names
+ * returned by readdir() are represented in the default ANSI code
+ * page while any output toconsole is typically formatted on another
+ * code page. Thus, non-ASCII characters in file names will not usually
+ * display correctly on console. The problem can be fixed in two ways:
+ * (1) change the character set of console to 1252 using chcp utility
+ * and use Lucida Console font, or (2) use _cprintf function when
+ * writing to console. The _cprinf() will re-encode ANSI strings to the
+ * console code page so many non-ASCII characters will display correcly.
+ */
+static struct dirent*
+readdir(DIR *dirp)
+{
+	WIN32_FIND_DATAW *datap;
+	struct dirent *entp;
+
+	/* Read next directory entry */
+	datap = dirent_next(dirp->wdirp);
+	if (datap) {
+		size_t n;
+		int error;
+
+		/* Attempt to convert file name to multi-byte string */
+		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
+			PATH_MAX, datap->cFileName, PATH_MAX);
+
+		/*
+		 * If the file name cannot be represented by a multi-byte
+		 * string, then attempt to use old 8+3 file name.
+		 * This allows traditional Unix-code to access some file
+		 * names despite of unicode characters, although file names
+		 * may seem unfamiliar to the user.
+		 *
+		 * Be ware that the code below cannot come up with a short
+		 * file name unless the file system provides one.  At least
+		 * VirtualBox shared folders fail to do this.
+		 */
+		if (error  &&  datap->cAlternateFileName[0] != '\0') {
+			error = dirent_wcstombs_s(
+				&n, dirp->ent.d_name, PATH_MAX,
+				datap->cAlternateFileName, PATH_MAX);
+		}
+
+		if (!error) {
+			DWORD attr;
+
+			/* Initialize directory entry for return */
+			entp = &dirp->ent;
+
+			/* Length of file name excluding zero terminator */
+			entp->d_namlen = n - 1;
+
+			/* File attributes */
+			attr = datap->dwFileAttributes;
+			if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
+				entp->d_type = DT_CHR;
+			else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+				entp->d_type = DT_DIR;
+			else
+				entp->d_type = DT_REG;
+
+			/* Reset dummy fields */
+			entp->d_ino = 0;
+			entp->d_reclen = sizeof(struct dirent);
+
+		} else {
+			/*
+			 * Cannot convert file name to multi-byte string so
+			 * construct an errornous directory entry and return
+			 * that. Note that we cannot return NULL as that would
+			 * stop the processing of directory entries completely.
+			 */
+			entp = &dirp->ent;
+			entp->d_name[0] = '?';
+			entp->d_name[1] = '\0';
+			entp->d_namlen = 1;
+			entp->d_type = DT_UNKNOWN;
+			entp->d_ino = 0;
+			entp->d_reclen = 0;
+		}
+
+	} else {
+		/* No more directory entries */
+		entp = NULL;
+	}
+
+	return entp;
+}
+
+/*
+ * Close directory stream.
+ */
+static int
+closedir(DIR *dirp)
+{
+	int ok;
+	if (dirp) {
+
+		/* Close wide-character directory stream */
+		ok = _wclosedir(dirp->wdirp);
+		dirp->wdirp = NULL;
+
+		/* Release multi-byte character version */
+		free(dirp);
+
+	} else {
+
+		/* Invalid directory stream */
+		dirent_set_errno(EBADF);
+		ok = /*failure*/-1;
+
+	}
+	return ok;
+}
+
+/* Convert multi-byte string to wide character string */
+static int
+dirent_mbstowcs_s(
+	size_t *pReturnValue,
+	wchar_t *wcstr,
+	size_t sizeInWords,
+	const char *mbstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = mbstowcs_s(pReturnValue, wcstr,
+	sizeInWords, mbstr, count);
+	#else
+
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to wide-character string (or count characters) */
+	n = mbstowcs(wcstr, mbstr, sizeInWords);
+	if (!wcstr || n < count) {
+
+		/* Zero-terminate output buffer */
+		if (wcstr  &&  sizeInWords) {
+			if (n >= sizeInWords)
+				n = sizeInWords - 1;
+			wcstr[n] = 0;
+		}
+
+		/* Length of resuting multi-byte string WITH zero
+		 *terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+
+		/* Success */
+		error = 0;
+
+	} else {
+
+		/* Could not convert string */
+		error = 1;
+
+	}
+	#endif
+
+	return error;
+}
+
+/* Convert wide-character string to multi-byte string */
+static int
+dirent_wcstombs_s(
+	size_t *pReturnValue,
+	char *mbstr,
+	size_t sizeInBytes, /* max size of mbstr */
+	const wchar_t *wcstr,
+	size_t count)
+{
+	int error;
+
+	#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 or later */
+	error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
+	#else
+	/* Older Visual Studio or non-Microsoft compiler */
+	size_t n;
+
+	/* Convert to multi-byte string
+	 * (or count the number of bytes needed)
+	 */
+	n = wcstombs(mbstr, wcstr, sizeInBytes);
+	if (!mbstr || n < count) {
+		/* Zero-terminate output buffer */
+		if (mbstr  &&  sizeInBytes) {
+			if (n >= sizeInBytes)
+				n = sizeInBytes - 1;
+			mbstr[n] = '\0';
+		}
+		/* Length of resulting multi-bytes string WITH
+		 *zero-terminator
+		 */
+		if (pReturnValue)
+			*pReturnValue = n + 1;
+		/* Success */
+		error = 0;
+	} else {
+		/* Cannot convert string */
+		error = 1;
+	}
+	#endif
+
+	return error;
+}
+
+/* Set errno variable */
+static void
+dirent_set_errno(int error)
+{
+#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
+	/* Microsoft Visual Studio 2005 and later */
+	_set_errno(error);
+#else
+
+	/* Non-Microsoft compiler or older Microsoft compiler */
+	errno = error;
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 3/9] eal: add additional function overrides in windows header files
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows Pallavi Kadam
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 2/9] eal: dirent.h implementation " Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:40                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 4/9] eal: getopt implementation for windows Pallavi Kadam
                                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/include/pthread.h  | 66 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/rte_os.h   | 42 ++++++++++++
 lib/librte_eal/windows/eal/include/sched.h    | 46 +++++++++++++
 .../windows/eal/include/sys/queue.h           |  8 +++
 4 files changed, 162 insertions(+)

diff --git a/lib/librte_eal/windows/eal/include/pthread.h b/lib/librte_eal/windows/eal/include/pthread.h
index 503329266..4ac24de0a 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) \
+	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..9e762617b 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,36 @@ 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);
+	if (buffer == NULL)
+		printf("Cannot allocate memory");
+
+	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 29868c93d..fbe07f742 100644
--- a/lib/librte_eal/windows/eal/include/sched.h
+++ b/lib/librte_eal/windows/eal/include/sched.h
@@ -39,6 +39,52 @@ typedef struct _rte_cpuset_s {
 			(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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _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_SETSIZE); _i++) \
+		(s)->_bits[_i] = -1LL; \
+} while (0)
+
+#define CPU_NOT(dst, src) \
+do { \
+	unsigned int _i; \
+	for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _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
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 4/9] eal: getopt implementation for windows
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (2 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:41                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 5/9] eal: add function to detect process type Pallavi Kadam
                                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding getopt files to support parsing option on
Windows.

The original contribution is under BSD-2 license.
https://github.com/greenplum-db/libusual/blob/master/usual/getopt.c
https://github.com/greenplum-db/libusual/blob/master/usual/getopt.h

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/getopt.c         | 470 ++++++++++++++++++++
 lib/librte_eal/windows/eal/include/getopt.h |  92 ++++
 lib/librte_eal/windows/eal/meson.build      |   1 +
 3 files changed, 563 insertions(+)
 create mode 100644 lib/librte_eal/windows/eal/getopt.c
 create mode 100644 lib/librte_eal/windows/eal/include/getopt.h

diff --git a/lib/librte_eal/windows/eal/getopt.c b/lib/librte_eal/windows/eal/getopt.c
new file mode 100644
index 000000000..170c9b5e0
--- /dev/null
+++ b/lib/librte_eal/windows/eal/getopt.c
@@ -0,0 +1,470 @@
+/* SPDX-License-Identifier: ISC AND BSD-2-Clause
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+#include <getopt.h>
+
+#ifdef NEED_USUAL_GETOPT
+
+#include <string.h>
+#include <stdlib.h>
+
+const char    *optarg;		/* argument associated with option */
+int	opterr = 1;		/* if error message should be printed */
+int	optind = 1;		/* index into parent argv vector */
+int	optopt = '?';		/* character checked for validity */
+
+static void pass(void) {}
+#define warnx(a, ...) pass()
+
+#define PRINT_ERROR	((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE	0x01	/* permute non-options to the end of argv */
+#define FLAG_ALLARGS	0x02	/* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY	0x04	/* operate as getopt_long_only */
+
+/* return values */
+#define	BADCH		((int)'?')
+#define	BADARG		((*options == ':') ? (int)':' : (int)'?')
+#define	INORDER		1
+
+#define	EMSG		""
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+	int c;
+
+	c = a % b;
+	while (c != 0) {
+		a = b;
+		b = c;
+		c = a % b;
+	}
+
+	return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+	char **nargv)
+{
+	int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+	char *swap;
+
+	/*
+	 * compute lengths of blocks and number and size of cycles
+	 */
+	nnonopts = panonopt_end - panonopt_start;
+	nopts = opt_end - panonopt_end;
+	ncycle = gcd(nnonopts, nopts);
+	cyclelen = (opt_end - panonopt_start) / ncycle;
+
+	for (i = 0; i < ncycle; i++) {
+		cstart = panonopt_end+i;
+		pos = cstart;
+		for (j = 0; j < cyclelen; j++) {
+			if (pos >= panonopt_end)
+				pos -= nnonopts;
+			else
+				pos += nopts;
+			swap = nargv[pos];
+			/* LINTED const cast */
+			((char **) nargv)[pos] = nargv[cstart];
+			/* LINTED const cast */
+			((char **)nargv)[cstart] = swap;
+		}
+	}
+}
+
+/*
+ * parse_long_options --
+ *	Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char **nargv, const char *options,
+	const struct option *long_options, int *idx, int short_too)
+{
+	const char *current_argv;
+	char *has_equal;
+	size_t current_argv_len;
+	int i, match;
+
+	current_argv = place;
+	match = -1;
+
+	optind++;
+
+	has_equal = strchr(current_argv, '=');
+	if (has_equal != NULL) {
+		/* argument found (--option=arg) */
+		current_argv_len = has_equal - current_argv;
+		has_equal++;
+	} else
+		current_argv_len = strlen(current_argv);
+
+	for (i = 0; long_options[i].name; i++) {
+		/* find matching long option */
+		if (strncmp(current_argv, long_options[i].name,
+		    current_argv_len))
+			continue;
+
+		if (strlen(long_options[i].name) == current_argv_len) {
+			/* exact match */
+			match = i;
+			break;
+		}
+		/*
+		 * If this is a known short option, don't allow
+		 * a partial match of a single character.
+		 */
+		if (short_too && current_argv_len == 1)
+			continue;
+
+		if (match == -1)	/* partial match */
+			match = i;
+		else {
+			/* ambiguous abbreviation */
+			if (PRINT_ERROR)
+				warnx(ambig, (int)current_argv_len,
+				     current_argv);
+			optopt = 0;
+			return BADCH;
+		}
+	}
+	if (match != -1) {		/* option found */
+		if (long_options[match].has_arg == no_argument
+		    && has_equal) {
+			if (PRINT_ERROR)
+				warnx(noarg, (int)current_argv_len,
+				     current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			return BADARG;
+		}
+		if (long_options[match].has_arg == required_argument ||
+		    long_options[match].has_arg == optional_argument) {
+			if (has_equal)
+				optarg = has_equal;
+			else if (long_options[match].has_arg ==
+			    required_argument) {
+				/*
+				 * optional argument doesn't use next nargv
+				 */
+				optarg = nargv[optind++];
+			}
+		}
+		if ((long_options[match].has_arg == required_argument)
+		    && (optarg == NULL)) {
+			/*
+			 * Missing argument; leading ':' indicates no error
+			 * should be generated.
+			 */
+			if (PRINT_ERROR)
+				warnx(recargstring,
+				    current_argv);
+			/*
+			 * XXX: GNU sets optopt to val regardless of flag
+			 */
+			if (long_options[match].flag == NULL)
+				optopt = long_options[match].val;
+			else
+				optopt = 0;
+			--optind;
+			return BADARG;
+		}
+	} else {			/* unknown option */
+		if (short_too) {
+			--optind;
+			return (-1);
+		}
+		if (PRINT_ERROR)
+			warnx(illoptstring, current_argv);
+		optopt = 0;
+		return BADCH;
+	}
+	if (idx)
+		*idx = match;
+	if (long_options[match].flag) {
+		*long_options[match].flag = long_options[match].val;
+		return 0;
+	} else
+		return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ *	Parse argc/argv argument vector.  Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char **nargv, const char *options,
+	const struct option *long_options, int *idx, int flags)
+{
+	char *oli;				/* option letter list index */
+	int optchar, short_too;
+	static int posixly_correct = -1;
+	char *buf;
+	size_t len;
+	int optreset = 0;
+
+	if (options == NULL)
+		return (-1);
+
+	/*
+	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
+	 * string begins with a '+'.
+	 */
+	if (posixly_correct == -1)
+		posixly_correct = _dupenv_s(&buf, &len, "POSIXLY_CORRECT");
+	if (!posixly_correct || *options == '+')
+		flags &= ~FLAG_PERMUTE;
+	else if (*options == '-')
+		flags |= FLAG_ALLARGS;
+	if (*options == '+' || *options == '-')
+		options++;
+	if (!posixly_correct)
+		free(buf);
+	/*
+	 * reset if requested
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	optarg = NULL;
+	if (optreset)
+		nonopt_start = nonopt_end = -1;
+start:
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc) {          /* end of argument vector */
+			place = EMSG;
+			if (nonopt_end != -1) {
+				/* do permutation, if we have to */
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			} else if (nonopt_start != -1) {
+				/*
+				 * If we skipped non-options, set optind
+				 * to the first of them.
+				 */
+				optind = nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+		place = nargv[optind];
+		if (*place != '-' ||
+		    (place[1] == '\0' && strchr(options, '-') == NULL)) {
+			place = EMSG;		/* found non-option */
+			if (flags & FLAG_ALLARGS) {
+				/*
+				 * GNU extension:
+				 * return non-option as argument to option 1
+				 */
+				optarg = nargv[optind++];
+				return INORDER;
+			}
+			if (!(flags & FLAG_PERMUTE)) {
+				/*
+				 * If no permutation wanted, stop parsing
+				 * at first non-option.
+				 */
+				return (-1);
+			}
+			/* do permutation */
+			if (nonopt_start == -1)
+				nonopt_start = optind;
+			else if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				nonopt_start = optind -
+				    (nonopt_end - nonopt_start);
+				nonopt_end = -1;
+			}
+			optind++;
+			/* process next argument */
+			goto start;
+		}
+		if (nonopt_start != -1 && nonopt_end == -1)
+			nonopt_end = optind;
+
+		/*
+		 * If we have "-" do nothing, if "--" we are done.
+		 */
+		if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+			optind++;
+			place = EMSG;
+			/*
+			 * We found an option (--), so if we skipped
+			 * non-options, we have to permute.
+			 */
+			if (nonopt_end != -1) {
+				permute_args(nonopt_start, nonopt_end,
+				    optind, nargv);
+				optind -= nonopt_end - nonopt_start;
+			}
+			nonopt_start = nonopt_end = -1;
+			return (-1);
+		}
+	}
+
+	/*
+	 * Check long options if:
+	 *  1) we were passed some
+	 *  2) the arg is not just "-"
+	 *  3) either the arg starts with -- we are getopt_long_only()
+	 */
+	if (long_options != NULL && place != nargv[optind] &&
+	    (*place == '-' || (flags & FLAG_LONGONLY))) {
+		short_too = 0;
+		if (*place == '-')
+			place++;		/* --foo long option */
+		else if (*place != ':' && strchr(options, *place) != NULL)
+			short_too = 1;		/* could be short option too */
+
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, short_too);
+		if (optchar != -1) {
+			place = EMSG;
+			return optchar;
+		}
+	}
+
+	optchar = (int)*place++;
+	oli = strchr(options, optchar);
+	if (optchar == (int)':' ||
+	    (optchar == (int)'-' && *place != '\0') ||
+	    oli == NULL) {
+		/*
+		 * If the user specified "-" and  '-' isn't listed in
+		 * options, return -1 (non-option) as per POSIX.
+		 * Otherwise, it is an unknown option character (or ':').
+		 */
+		if (optchar == (int)'-' && *place == '\0')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (PRINT_ERROR)
+			warnx(illoptchar, optchar);
+		optopt = optchar;
+		return BADCH;
+	}
+	if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+		/* -W long-option */
+		if (*place)
+			;
+		else if (++optind >= nargc) {	/* no arg */
+			place = EMSG;
+			if (PRINT_ERROR)
+				warnx(recargchar, optchar);
+			optopt = optchar;
+			return BADARG;
+		}				/* white space */
+		place = nargv[optind];
+		optchar = parse_long_options(nargv, options, long_options,
+		    idx, 0);
+		place = EMSG;
+		return optchar;
+	}
+	if (*++oli != ':') {			/* doesn't take argument */
+		if (!*place)
+			++optind;
+	} else {				/* takes (optional) argument */
+		optarg = NULL;
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (oli[1] != ':') {	/* arg not optional */
+			if (++optind >= nargc) {	/* no arg */
+				place = EMSG;
+				if (PRINT_ERROR)
+					warnx(recargchar, optchar);
+				optopt = optchar;
+				return BADARG;
+			}
+			optarg = nargv[optind];
+		}
+		place = EMSG;
+		++optind;
+	}
+	/* dump back option letter */
+	return optchar;
+}
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char *nargv[], const char *options)
+{
+	return getopt_internal(nargc, nargv, options, NULL, NULL,
+			       FLAG_PERMUTE);
+}
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char *nargv[], const char *options,
+	const struct option *long_options, int *idx)
+{
+
+	return (getopt_internal(nargc, nargv, options, long_options, idx,
+	    FLAG_PERMUTE|FLAG_LONGONLY));
+}
+
+#endif /* NEED_USUAL_GETOPT */
diff --git a/lib/librte_eal/windows/eal/include/getopt.h b/lib/librte_eal/windows/eal/include/getopt.h
new file mode 100644
index 000000000..2eebe54e3
--- /dev/null
+++ b/lib/librte_eal/windows/eal/include/getopt.h
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ */
+
+/**
+ * @file
+ * getopt compat.
+ *
+ * This module provides getopt() and getopt_long().
+ */
+
+#ifndef _USUAL_GETOPT_H_
+#define _USUAL_GETOPT_H_
+
+#ifndef NEED_USUAL_GETOPT
+#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
+	!defined(HAVE_GETOPT_LONG)
+#define NEED_USUAL_GETOPT
+#endif
+#endif
+
+#ifndef NEED_USUAL_GETOPT
+
+/* Use system getopt */
+#include <getopt.h>
+
+#else /* NEED_USUAL_GETOPT */
+
+/* avoid name collision */
+#define optarg usual_optarg
+#define opterr usual_opterr
+#define optind usual_optind
+#define optopt usual_optopt
+#define getopt(a, b, c) usual_getopt(a, b, c)
+#define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
+
+
+/** argument to current option, or NULL if it has none */
+extern const char *optarg;
+/** Current position in arg string.  Starts from 1.
+ * Setting to 0 resets state.
+ */
+extern int optind;
+/** whether getopt() should print error messages on problems.  Default: 1. */
+extern int opterr;
+/** Option char which caused error */
+extern int optopt;
+
+/** long option takes no argument */
+#define no_argument        0
+/** long option requires argument */
+#define required_argument  1
+/** long option has optional argument */
+#define optional_argument  2
+
+/** Long option description */
+struct option {
+	/** name of long option */
+	const char *name;
+
+	/**
+	 * whether option takes an argument.
+	 * One of no_argument, required_argument, and optional_argument.
+	 */
+	int has_arg;
+
+	/** if not NULL, set *flag to val when option found */
+	int *flag;
+
+	/** if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+/** Compat: getopt */
+int getopt(int argc, char *argv[], const char *options);
+
+/** Compat: getopt_long */
+int getopt_long(int argc, char *argv[], const char *options,
+		const struct option *longopts, int *longindex);
+
+/** Compat: getopt_long_only */
+int getopt_long_only(int nargc, char *argv[], const char *options,
+		     const struct option *long_options, int *idx);
+
+
+#endif /* NEED_USUAL_GETOPT */
+
+#endif /* !_USUAL_GETOPT_H_ */
diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index af4f70f00..d37222158 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -17,4 +17,5 @@ env_sources = files('eal.c',
 	'eal_debug.c',
 	'eal_lcore.c',
 	'eal_thread.c',
+	'getopt.c',
 )
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 5/9] eal: add function to detect process type
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (3 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 4/9] eal: getopt implementation for windows Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:42                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 6/9] eal: include SSE4 support for windows Pallavi Kadam
                                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding a function to detect process type, also included
header files to contain suitable function declarations
and to support extra warning flags.

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/windows/eal/eal.c        | 61 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_debug.c  |  1 +
 lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
 lib/librte_eal/windows/eal/eal_thread.c | 11 +++++
 4 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index ce460481f..6a1208c35 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,48 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
+#include <eal_options.h>
 #include <eal_private.h>
 
+/* define fd variable here, because file needs to be kept open for the
+ * duration of the program, as we hold a write lock on it in the primary proc
+ */
+static int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
 /* Address of global and public configuration */
-static struct rte_config rte_config;
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
 
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* internal configuration */
+struct internal_config internal_config;
+
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+const char *
+rte_eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +51,38 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are a secondary
+	 * process. NOTE: if we get a file handle back, we keep that open
+	 * and don't close it to prevent a race condition between multiple opens
+	 */
+	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
+		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
+	if (err == 0) {
+		OVERLAPPED soverlapped = { 0 };
+		soverlapped.Offset = sizeof(*rte_config.mem_config);
+		soverlapped.OffsetHigh = 0;
+
+		HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
+
+		if (!LockFileEx(hwinfilehandle,
+			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
+			sizeof(*rte_config.mem_config), 0, &soverlapped))
+			ptype = RTE_PROC_SECONDARY;
+	}
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c
index edcf257cc..669be6ff9 100644
--- a/lib/librte_eal/windows/eal/eal_debug.c
+++ b/lib/librte_eal/windows/eal/eal_debug.c
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c
index d39f348a3..b3a6c63af 100644
--- a/lib/librte_eal/windows/eal/eal_lcore.c
+++ b/lib/librte_eal/windows/eal/eal_lcore.c
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
 	unsigned int total_procs;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 0591d4c7f..9e4bbaa08 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,11 +10,14 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #include "eal_private.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;
+RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
 
 /*
  * Send a message to a slave lcore identified by slave_id to call a
@@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread)
 
 	return 0;
 }
+
+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;
+}
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 6/9] eal: include SSE4 support for windows
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (4 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 5/9] eal: add function to detect process type Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:42                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 7/9] eal: remove syslog and dlfcn " Pallavi Kadam
                                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Modified \common\include\arch\x86\rte_vect.h
to include SSE4 header for Windows.

Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/common/include/arch/x86/rte_vect.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/arch/x86/rte_vect.h b/lib/librte_eal/common/include/arch/x86/rte_vect.h
index cf4e9db38..df5a60762 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_vect.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_vect.h
@@ -15,7 +15,9 @@
 #include <rte_config.h>
 #include "generic/rte_vect.h"
 
-#if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
+#if (defined(__ICC) || \
+	(defined(_WIN64)) || \
+	(__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
 
 #include <smmintrin.h> /* SSE4 */
 
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 7/9] eal: remove syslog and dlfcn support for windows
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (5 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 6/9] eal: include SSE4 support for windows Pallavi Kadam
@ 2020-02-07  3:14                 ` " Pallavi Kadam
  2020-02-12  0:42                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 8/9] build: add additional common files support Pallavi Kadam
                                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Excluding syslog/ dlfcn definitions and parameters
from Windows by adding #ifndef RTE_EXEC_ENV_WINDOWS.

Note: This is a temporary change. In future, separate
'unix' directory will be created for unix specific functions.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 5920233bc..75974dd5b 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -6,12 +6,16 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
+#endif
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
@@ -205,7 +209,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	}
 	internal_cfg->base_virtaddr = 0;
 
+#ifdef LOG_DAEMON
 	internal_cfg->syslog_facility = LOG_DAEMON;
+#endif
 
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
@@ -278,6 +284,7 @@ eal_plugindir_init(const char *path)
 int
 eal_plugins_init(void)
 {
+#ifndef RTE_EXEC_ENV_WINDOWS
 	struct shared_driver *solib = NULL;
 	struct stat sb;
 
@@ -306,6 +313,7 @@ eal_plugins_init(void)
 
 	}
 	return 0;
+#endif
 }
 
 /*
@@ -927,6 +935,7 @@ eal_parse_lcores(const char *lcores)
 	return ret;
 }
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 static int
 eal_parse_syslog(const char *facility, struct internal_config *conf)
 {
@@ -965,6 +974,7 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 	}
 	return -1;
 }
+#endif
 
 static int
 eal_parse_log_priority(const char *level)
@@ -1389,6 +1399,7 @@ eal_parse_common_option(int opt, const char *optarg,
 		}
 		break;
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 	case OPT_SYSLOG_NUM:
 		if (eal_parse_syslog(optarg, conf) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameters for --"
@@ -1396,6 +1407,7 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
+#endif
 
 	case OPT_LOG_LEVEL_NUM: {
 		if (eal_parse_log_level(optarg) < 0) {
@@ -1675,7 +1687,9 @@ eal_common_usage(void)
 	       "                      (can be used multiple times)\n"
 	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
 	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
+#ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
+#endif
 	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
 	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
 	       "                      Set specific log level\n"
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 8/9] build: add additional common files support
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (6 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 7/9] eal: remove syslog and dlfcn " Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:42                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
                                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Added support for additional common files in meson build
to expand Windows EAL and to support the lcore parsing
feature on Windows.

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/windows/eal/meson.build | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/meson.build b/lib/librte_eal/windows/eal/meson.build
index d37222158..2a062c365 100644
--- a/lib/librte_eal/windows/eal/meson.build
+++ b/lib/librte_eal/windows/eal/meson.build
@@ -8,10 +8,16 @@ env_headers = files(
 	'include/rte_os.h',
 )
 common_sources = files(
+	'../../common/eal_common_bus.c',
+	'../../common/eal_common_class.c',
+	'../../common/eal_common_devargs.c',
 	'../../common/eal_common_errno.c',
 	'../../common/eal_common_launch.c',
 	'../../common/eal_common_lcore.c',
-	'../../common/eal_common_log.c'
+	'../../common/eal_common_log.c',
+	'../../common/eal_common_options.c',
+	'../../common/eal_common_thread.c',
+	'../../common/rte_option.c',
 )
 env_sources = files('eal.c',
 	'eal_debug.c',
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* [dpdk-dev] [PATCH v8 9/9] eal: add minimum viable code to support parsing
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (7 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 8/9] build: add additional common files support Pallavi Kadam
@ 2020-02-07  3:14                 ` Pallavi Kadam
  2020-02-12  0:43                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  2020-02-07 19:05                 ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Dmitry Kozlyuk
                                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:14 UTC (permalink / raw)
  To: dev, thomas
  Cc: Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	pallavi.kadam

Adding specific logic for eal.c to support parsing on
Windows.

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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 6a1208c35..5c8e7f472 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -16,6 +16,9 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+ /* Allow the application to print its usage message too if set */
+static rte_usage_hook_t	rte_application_usage_hook;
+
 /* define fd variable here, because file needs to be kept open for the
  * duration of the program, as we hold a write lock on it in the primary proc
  */
@@ -83,6 +86,124 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
+/* display usage */
+static void
+eal_usage(const char *prgname)
+{
+	printf("\nUsage: %s ", prgname);
+	eal_common_usage();
+	/* Allow the application to print its usage message too
+	 *if hook is set
+	 */
+	if (rte_application_usage_hook) {
+		printf("===== Application Usage =====\n\n");
+		rte_application_usage_hook(prgname);
+	}
+}
+
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM) ?
+			eal_parse_common_option(opt, optarg,
+				&internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
+/* Parse the argument given in the command line of the application */
+__attribute__((optnone)) static int
+eal_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt;
+	int option_index;
+	char *prgname = argv[0];
+
+	argvopt = argv;
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+		eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?') {
+			eal_usage(prgname);
+			return -1;
+		}
+
+		ret = eal_parse_common_option(opt, optarg, &internal_config);
+		/* common parser is not happy */
+		if (ret < 0) {
+			eal_usage(prgname);
+			return -1;
+		}
+		/* common parser handled this option */
+		if (ret == 0)
+			continue;
+
+		switch (opt) {
+		case 'h':
+			eal_usage(prgname);
+			exit(EXIT_SUCCESS);
+		default:
+			if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
+				RTE_LOG(ERR, EAL, "Option %c is not supported "
+					"on Windows\n", opt);
+			} else if (opt >= OPT_LONG_MIN_NUM &&
+				opt < OPT_LONG_MAX_NUM) {
+				RTE_LOG(ERR, EAL, "Option %s is not supported "
+					"on Windows\n",
+					eal_long_options[option_index].name);
+			} else {
+				RTE_LOG(ERR, EAL, "Option %d is not supported "
+					"on Windows\n", opt);
+			}
+			eal_usage(prgname);
+			return -1;
+		}
+	}
+
+	if (eal_adjust_config(&internal_config) != 0)
+		return -1;
+
+	/* sanity checks */
+	if (eal_check_common_options(&internal_config) != 0) {
+		eal_usage(prgname);
+		return -1;
+	}
+
+	if (optind >= 0)
+		argv[optind - 1] = prgname;
+	ret = optind - 1;
+	optind = 0; /* reset getopt lib */
+	return ret;
+}
+
 static int
 sync_func(void *arg __rte_unused)
 {
@@ -98,9 +219,11 @@ rte_eal_init_alert(const char *msg)
 
  /* Launch threads, called at application init(). */
 int
-rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
+rte_eal_init(int argc, char **argv)
 {
-	int i;
+	int i, fctret;
+
+	eal_log_level_parse(argc, argv);
 
 	/* create a map of all processors in the system */
 	eal_create_cpu_map();
@@ -111,6 +234,10 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 		return -1;
 	}
 
+	fctret = eal_parse_args(argc, argv);
+	if (fctret < 0)
+		exit(1);
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
@@ -139,5 +266,5 @@ rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
 	 */
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
-	return 0;
+	return fctret;
 }
-- 
2.18.0.windows.1


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  6:41                       ` Dmitry Kozlyuk
  2020-02-06  9:26                         ` Thomas Monjalon
@ 2020-02-07  3:45                         ` " Pallavi Kadam
  1 sibling, 0 replies; 149+ messages in thread
From: Pallavi Kadam @ 2020-02-07  3:45 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

Hi Dmitry,

On 2/5/2020 10:41 PM, Dmitry Kozlyuk wrote:
>
>> On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
>>>
>>> On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:
>>>> Crashes at argument parsing, WinDbg log attached.
>>> This patch works fine with meson=0.49.
>>> I was able to execute the 'helloworld' app.
>>>
>>> When I tried to build with meson=0.52 it failed with the error:
>>> [9/25] Linking target lib/librte_kvargs-20.0.dll.
>>> FAILED: lib/librte_kvargs-20.0.dll
>>> clang @lib/librte_kvargs-20.0.dll.rsp
>>> clang: error: no such file or directory: '/OPT:REF'
>> Fixed this error with the patch you sent before.
>> were able to execute parsing:
>>
>> $ ./build/examples/dpdk-helloworld.exe -l 4-8
>> EAL: Detected 20 lcore(s)
>> EAL: Detected 2 NUMA nodes
>> hello from core 5
>> hello from core 6
>> hello from core 7
>> hello from core 8
>> hello from core 4
>>
>>> Not completely sure, if this could be the reason for the crash.
> The crash does not happen with any arguments, "-l 4-8" works fine as do
> "-cf" and "-v", but "--log-level=eal:8" crashes reproducibly. I assume
> application should not crash on invalid options, but report an error and exit.
> For the reference, I applied your patchset to the latest dpdk:master.
>
> Z:\>build\native\clang\examples\dpdk-helloworld.exe
> EAL: Detected 4 lcore(s)
> EAL: Detected 1 NUMA nodes
>
> 	OK, no lcores specified.
>
> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf
> EAL: Detected 4 lcore(s)
> EAL: Detected 1 NUMA nodes
> hello from core 1
> hello from core 2
> hello from core 3
> hello from core 0
>
> 	OK, 4 lcores enabled.
>
> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf --log-level=eal:8
>
> 	Crash, WinDbg log attached to bug report.
>
> Z:\>echo %errorlevel%
> -1073741819
>
> Z:\>
>
> Attaching the build log, but I don't think it matters, it's something with
> getopt implementation or it's use, judging by stack trace.

Thanks for the detailed log.
There was bit size issue in getopt file. We fixed the issue.
Please try v8 and let us know.

>
> P.S. I can also see "--syslog" option in the help message, you should
> probably hide it via #ifndef, as you did with said option handling.

Incorporated in v8. Thanks

>

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  9:26                         ` Thomas Monjalon
@ 2020-02-07 16:46                           ` Ranjit Menon
  2020-02-07 17:17                             ` Ranjit Menon
  2020-02-08  0:43                           ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
  1 sibling, 1 reply; 149+ messages in thread
From: Ranjit Menon @ 2020-02-07 16:46 UTC (permalink / raw)
  To: Thomas Monjalon, Pallavi Kadam, Dmitry Kozlyuk, Harini.Ramakrishnan
  Cc: dev, keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	antara.ganesh.kolar

On 2/6/2020 1:26 AM, Thomas Monjalon wrote:
> As discussed in community meeting, the goal was to have core parsing
> in Windows EAL 20.02.
> Given that there is a crash and a doubt on the imported getopt library,
> I think it's better to postpone this series to 20.05.
> 
> 

Thomas...
We have fixed the crash in the v8 series of this patch - Pallavi sent it 
out for review last night. (It was a simple fix)

Can we please get this merged into 20.02? It would be great to progress 
Windows support in this release. (The initial Windows support was merged 
in 19.02, so it's been a year since we moved it forward! :-))

thanks,

Ranjit

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-07 16:46                           ` Ranjit Menon
@ 2020-02-07 17:17                             ` Ranjit Menon
  0 siblings, 0 replies; 149+ messages in thread
From: Ranjit Menon @ 2020-02-07 17:17 UTC (permalink / raw)
  To: Thomas Monjalon, Pallavi Kadam, Dmitry Kozlyuk, harini.ramakrishnan
  Cc: dev, keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	antara.ganesh.kolar

On 2/7/2020 8:46 AM, Ranjit Menon wrote:
> On 2/6/2020 1:26 AM, Thomas Monjalon wrote:
> > As discussed in community meeting, the goal was to have core parsing
> > in Windows EAL 20.02.
> > Given that there is a crash and a doubt on the imported getopt library,
> > I think it's better to postpone this series to 20.05.
> >
> >
>
> Thomas...
> We have fixed the crash in the v8 series of this patch - Pallavi sent it
> out for review last night. (It was a simple fix)
>
> Can we please get this merged into 20.02? It would be great to progress
> Windows support in this release. (The initial Windows support was merged
> in 19.02, so it's been a year since we moved it forward! :-))
>
> thanks,
>
> Ranjit
Sorry, I believe the initial patches were merged in 19.05, still a long time!

@Dmitry: If you could do some rudimentary tests and ACK the v8 series of this patch, it would be very helpful.
thanks,

Ranjit

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (8 preceding siblings ...)
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-02-07 19:05                 ` Dmitry Kozlyuk
  2020-02-12 21:52                   ` Thomas Monjalon
  2020-02-08  0:36                 ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
                                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 149+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-07 19:05 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, thomas, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
> 
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
> 
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
> 

Observing no issues on Windows 10, Meson 0.53.999, Clang 9.0.1.

Reviewed-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

-- 
Dmitry Kozlyuk

^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (9 preceding siblings ...)
  2020-02-07 19:05                 ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Dmitry Kozlyuk
@ 2020-02-08  0:36                 ` " Narcisa Ana Maria Vasile
  2020-02-08  1:04                 ` Narcisa Ana Maria Vasile
                                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-08  0:36 UTC (permalink / raw)
  To: dev, Pallavi Kadam, Ranjit Menon

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
>
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
>
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
>
> v7 changes:
> 	Removed Windows "eal_filesystem.h" for now and will be added
> 	later if required. Currently, Windows EAL uses common version
> 	of eal_filesystem.h.
>
> v6 changes:
> 	Removed sysfs function as it was not required on Windows.
> 	Removed syslog and dlfcn support for Windows.
>
> v5 changes:
> 	Fixed indentation in patch 6.
>
> v4 changes:
> 	Modified license/exceptions.txt file.
> 	The following files in this patch-set require license exceptions as
> 	listed:
> 	dirent.h      MIT license
> 	getopt.h      BSD-2-Clause license
> 	getopt.c      ISC and BSD-2-Clause license
>
> 	Removed syslog file in Windows and added ifndef Windows around syslog
> 	classification parameters in the common code.
>
> v3 Changes:
>  	Modified generic rte_vect to add Windows support.
> 	Moved RTE_CPU* definitions to OS specific file.
> 	Added SPDX tag on top of third party files.
>
> v2 Changes:
> 	syslog.h: Replaced the BSD license boilerplate to SPDX tag.
>
>
> Pallavi Kadam (9):
>   license: add license exception for windows
>   eal: dirent.h implementation for windows
>   eal: add additional function overrides in windows header files
>   eal: getopt implementation for windows
>   eal: add function to detect process type
>   eal: include SSE4 support for windows
>   eal: remove syslog and dlfcn support for windows
>   build: add additional common files support
>   eal: add minimum viable code to support parsing
>
>  lib/librte_eal/common/eal_common_options.c    |  14 +
>  .../common/include/arch/x86/rte_vect.h        |   4 +-
>  lib/librte_eal/windows/eal/eal.c              | 194 ++++-
>  lib/librte_eal/windows/eal/eal_debug.c        |   1 +
>  lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
>  lib/librte_eal/windows/eal/eal_thread.c       |  11 +
>  lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
>  lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
>  lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
>  lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
>  lib/librte_eal/windows/eal/include/sched.h    |  46 ++
>  .../windows/eal/include/sys/queue.h           |   8 +
>  lib/librte_eal/windows/eal/meson.build        |   9 +-
>  license/exceptions.txt                        |  12 +-
>  15 files changed, 1625 insertions(+), 11 deletions(-)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by Narcisa Vasile <navasile@microsoft.com>

Acked-by Narcisa Vasile <navasile@microsoft.com>




^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] Re: [PATCH v7 9/9] eal: add minimum viable code to support parsing
  2020-02-06  9:26                         ` Thomas Monjalon
  2020-02-07 16:46                           ` Ranjit Menon
@ 2020-02-08  0:43                           ` " Narcisa Ana Maria Vasile
  1 sibling, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-08  0:43 UTC (permalink / raw)
  To: Thomas Monjalon, Pallavi Kadam, Dmitry Kozlyuk,
	Harini Ramakrishnan, ranjit.menon
  Cc: dev, keith.wiles, bruce.richardson, david.marchand, jerinjacobk,
	antara.ganesh.kolar

On 2/6/2020 1:26 AM, Thomas Monjalon wrote:
> As discussed in community meeting, the goal was to have core parsing
> in Windows EAL 20.02.
> Given that there is a crash and a doubt on the imported getopt library,
> I think it's better to postpone this series to 20.05.

The crash is now fixed in the last patchset version.

I tested and observed no crashes.

>
> 06/02/2020 07:41, Dmitry Kozlyuk:
>>> On 2/5/2020 4:39 PM, Pallavi Kadam wrote:
>>>> On 2/5/2020 11:54 AM, Dmitry Kozlyuk wrote:  
>>>>> Crashes at argument parsing, WinDbg log attached.  
>>>> This patch works fine with meson=0.49.
>>>> I was able to execute the 'helloworld' app.
>>>>
>>>> When I tried to build with meson=0.52 it failed with the error:
>>>> [9/25] Linking target lib/librte_kvargs-20.0.dll.
>>>> FAILED: lib/librte_kvargs-20.0.dll
>>>> clang @lib/librte_kvargs-20.0.dll.rsp
>>>> clang: error: no such file or directory: '/OPT:REF'  
>>> Fixed this error with the patch you sent before.
>>> were able to execute parsing:
>>>
>>> $ ./build/examples/dpdk-helloworld.exe -l 4-8
>>> EAL: Detected 20 lcore(s)
>>> EAL: Detected 2 NUMA nodes
>>> hello from core 5
>>> hello from core 6
>>> hello from core 7
>>> hello from core 8
>>> hello from core 4
>>>
>>>> Not completely sure, if this could be the reason for the crash.  
>> The crash does not happen with any arguments, "-l 4-8" works fine as do
>> "-cf" and "-v", but "--log-level=eal:8" crashes reproducibly. I assume
>> application should not crash on invalid options, but report an error and exit.
>> For the reference, I applied your patchset to the latest dpdk:master.
>>
>> Z:\>build\native\clang\examples\dpdk-helloworld.exe
>> EAL: Detected 4 lcore(s)
>> EAL: Detected 1 NUMA nodes
>>
>> 	OK, no lcores specified.
>>
>> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf
>> EAL: Detected 4 lcore(s)
>> EAL: Detected 1 NUMA nodes
>> hello from core 1
>> hello from core 2
>> hello from core 3
>> hello from core 0
>>
>> 	OK, 4 lcores enabled.
>>
>> Z:\>build\native\clang\examples\dpdk-helloworld.exe -cf --log-level=eal:8
>>
>> 	Crash, WinDbg log attached to bug report.
>>
>> Z:\>echo %errorlevel%
>> -1073741819
>>
>> Z:\>
>>
>> Attaching the build log, but I don't think it matters, it's something with
>> getopt implementation or it's use, judging by stack trace.
>>
>> P.S. I can also see "--syslog" option in the help message, you should
>> probably hide it via #ifndef, as you did with said option handling.
>
>
>
>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (10 preceding siblings ...)
  2020-02-08  0:36                 ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
@ 2020-02-08  1:04                 ` Narcisa Ana Maria Vasile
  2020-02-10 20:32                 ` Narcisa Ana Maria Vasile
                                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-08  1:04 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
>
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
>
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
>
> v7 changes:
> 	Removed Windows "eal_filesystem.h" for now and will be added
> 	later if required. Currently, Windows EAL uses common version
> 	of eal_filesystem.h.
>
> v6 changes:
> 	Removed sysfs function as it was not required on Windows.
> 	Removed syslog and dlfcn support for Windows.
>
> v5 changes:
> 	Fixed indentation in patch 6.
>
> v4 changes:
> 	Modified license/exceptions.txt file.
> 	The following files in this patch-set require license exceptions as
> 	listed:
> 	dirent.h      MIT license
> 	getopt.h      BSD-2-Clause license
> 	getopt.c      ISC and BSD-2-Clause license
>
> 	Removed syslog file in Windows and added ifndef Windows around syslog
> 	classification parameters in the common code.
>
> v3 Changes:
>  	Modified generic rte_vect to add Windows support.
> 	Moved RTE_CPU* definitions to OS specific file.
> 	Added SPDX tag on top of third party files.
>
> v2 Changes:
> 	syslog.h: Replaced the BSD license boilerplate to SPDX tag.
>
>
> Pallavi Kadam (9):
>   license: add license exception for windows
>   eal: dirent.h implementation for windows
>   eal: add additional function overrides in windows header files
>   eal: getopt implementation for windows
>   eal: add function to detect process type
>   eal: include SSE4 support for windows
>   eal: remove syslog and dlfcn support for windows
>   build: add additional common files support
>   eal: add minimum viable code to support parsing
>
>  lib/librte_eal/common/eal_common_options.c    |  14 +
>  .../common/include/arch/x86/rte_vect.h        |   4 +-
>  lib/librte_eal/windows/eal/eal.c              | 194 ++++-
>  lib/librte_eal/windows/eal/eal_debug.c        |   1 +
>  lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
>  lib/librte_eal/windows/eal/eal_thread.c       |  11 +
>  lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
>  lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
>  lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
>  lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
>  lib/librte_eal/windows/eal/include/sched.h    |  46 ++
>  .../windows/eal/include/sys/queue.h           |   8 +
>  lib/librte_eal/windows/eal/meson.build        |   9 +-
>  license/exceptions.txt                        |  12 +-
>  15 files changed, 1625 insertions(+), 11 deletions(-)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by: Narcisa Vasile <navasile@microsoft.com>

Acked-by: Narcisa Vasile <navasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (11 preceding siblings ...)
  2020-02-08  1:04                 ` Narcisa Ana Maria Vasile
@ 2020-02-10 20:32                 ` Narcisa Ana Maria Vasile
  2020-02-10 21:22                 ` Narcisa Ana Maria Vasile
  2020-02-11 21:25                 ` Narcisa Ana Maria Vasile
  14 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-10 20:32 UTC (permalink / raw)
  To: dev

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
>
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
>
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
>
> v7 changes:
> 	Removed Windows "eal_filesystem.h" for now and will be added
> 	later if required. Currently, Windows EAL uses common version
> 	of eal_filesystem.h.
>
> v6 changes:
> 	Removed sysfs function as it was not required on Windows.
> 	Removed syslog and dlfcn support for Windows.
>
> v5 changes:
> 	Fixed indentation in patch 6.
>
> v4 changes:
> 	Modified license/exceptions.txt file.
> 	The following files in this patch-set require license exceptions as
> 	listed:
> 	dirent.h      MIT license
> 	getopt.h      BSD-2-Clause license
> 	getopt.c      ISC and BSD-2-Clause license
>
> 	Removed syslog file in Windows and added ifndef Windows around syslog
> 	classification parameters in the common code.
>
> v3 Changes:
>  	Modified generic rte_vect to add Windows support.
> 	Moved RTE_CPU* definitions to OS specific file.
> 	Added SPDX tag on top of third party files.
>
> v2 Changes:
> 	syslog.h: Replaced the BSD license boilerplate to SPDX tag.
>
>
> Pallavi Kadam (9):
>   license: add license exception for windows
>   eal: dirent.h implementation for windows
>   eal: add additional function overrides in windows header files
>   eal: getopt implementation for windows
>   eal: add function to detect process type
>   eal: include SSE4 support for windows
>   eal: remove syslog and dlfcn support for windows
>   build: add additional common files support
>   eal: add minimum viable code to support parsing
>
>  lib/librte_eal/common/eal_common_options.c    |  14 +
>  .../common/include/arch/x86/rte_vect.h        |   4 +-
>  lib/librte_eal/windows/eal/eal.c              | 194 ++++-
>  lib/librte_eal/windows/eal/eal_debug.c        |   1 +
>  lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
>  lib/librte_eal/windows/eal/eal_thread.c       |  11 +
>  lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
>  lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
>  lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
>  lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
>  lib/librte_eal/windows/eal/include/sched.h    |  46 ++
>  .../windows/eal/include/sys/queue.h           |   8 +
>  lib/librte_eal/windows/eal/meson.build        |   9 +-
>  license/exceptions.txt                        |  12 +-
>  15 files changed, 1625 insertions(+), 11 deletions(-)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by: Narcisa Vasile <navasile@microsoft.com>

Acked-by: Narcisa Vasile <navasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (12 preceding siblings ...)
  2020-02-10 20:32                 ` Narcisa Ana Maria Vasile
@ 2020-02-10 21:22                 ` Narcisa Ana Maria Vasile
  2020-02-11 21:25                 ` Narcisa Ana Maria Vasile
  14 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-10 21:22 UTC (permalink / raw)
  To: dev

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
>
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
>
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
>
> v7 changes:
> 	Removed Windows "eal_filesystem.h" for now and will be added
> 	later if required. Currently, Windows EAL uses common version
> 	of eal_filesystem.h.
>
> v6 changes:
> 	Removed sysfs function as it was not required on Windows.
> 	Removed syslog and dlfcn support for Windows.
>
> v5 changes:
> 	Fixed indentation in patch 6.
>
> v4 changes:
> 	Modified license/exceptions.txt file.
> 	The following files in this patch-set require license exceptions as
> 	listed:
> 	dirent.h      MIT license
> 	getopt.h      BSD-2-Clause license
> 	getopt.c      ISC and BSD-2-Clause license
>
> 	Removed syslog file in Windows and added ifndef Windows around syslog
> 	classification parameters in the common code.
>
> v3 Changes:
>  	Modified generic rte_vect to add Windows support.
> 	Moved RTE_CPU* definitions to OS specific file.
> 	Added SPDX tag on top of third party files.
>
> v2 Changes:
> 	syslog.h: Replaced the BSD license boilerplate to SPDX tag.
>
>
> Pallavi Kadam (9):
>   license: add license exception for windows
>   eal: dirent.h implementation for windows
>   eal: add additional function overrides in windows header files
>   eal: getopt implementation for windows
>   eal: add function to detect process type
>   eal: include SSE4 support for windows
>   eal: remove syslog and dlfcn support for windows
>   build: add additional common files support
>   eal: add minimum viable code to support parsing
>
>  lib/librte_eal/common/eal_common_options.c    |  14 +
>  .../common/include/arch/x86/rte_vect.h        |   4 +-
>  lib/librte_eal/windows/eal/eal.c              | 194 ++++-
>  lib/librte_eal/windows/eal/eal_debug.c        |   1 +
>  lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
>  lib/librte_eal/windows/eal/eal_thread.c       |  11 +
>  lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
>  lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
>  lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
>  lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
>  lib/librte_eal/windows/eal/include/sched.h    |  46 ++
>  .../windows/eal/include/sys/queue.h           |   8 +
>  lib/librte_eal/windows/eal/meson.build        |   9 +-
>  license/exceptions.txt                        |  12 +-
>  15 files changed, 1625 insertions(+), 11 deletions(-)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07  3:14               ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Pallavi Kadam
                                   ` (13 preceding siblings ...)
  2020-02-10 21:22                 ` Narcisa Ana Maria Vasile
@ 2020-02-11 21:25                 ` Narcisa Ana Maria Vasile
  14 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-11 21:25 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> This patchset includes additional functionalities for Windows EAL
> to support command-line parsing feature and some EAL common code
> on Windows.
>
> This patchset can be applied to windpdk-next-dev branch in the draft repo.
>
> v8 changes:
> 	Fixed the naming conventions.
> 	Fixed a crash encountered due to getopt function.
> 	Removed "--syslog" from help options for Windows.
>
> v7 changes:
> 	Removed Windows "eal_filesystem.h" for now and will be added
> 	later if required. Currently, Windows EAL uses common version
> 	of eal_filesystem.h.
>
> v6 changes:
> 	Removed sysfs function as it was not required on Windows.
> 	Removed syslog and dlfcn support for Windows.
>
> v5 changes:
> 	Fixed indentation in patch 6.
>
> v4 changes:
> 	Modified license/exceptions.txt file.
> 	The following files in this patch-set require license exceptions as
> 	listed:
> 	dirent.h      MIT license
> 	getopt.h      BSD-2-Clause license
> 	getopt.c      ISC and BSD-2-Clause license
>
> 	Removed syslog file in Windows and added ifndef Windows around syslog
> 	classification parameters in the common code.
>
> v3 Changes:
>  	Modified generic rte_vect to add Windows support.
> 	Moved RTE_CPU* definitions to OS specific file.
> 	Added SPDX tag on top of third party files.
>
> v2 Changes:
> 	syslog.h: Replaced the BSD license boilerplate to SPDX tag.
>
>
> Pallavi Kadam (9):
>   license: add license exception for windows
>   eal: dirent.h implementation for windows
>   eal: add additional function overrides in windows header files
>   eal: getopt implementation for windows
>   eal: add function to detect process type
>   eal: include SSE4 support for windows
>   eal: remove syslog and dlfcn support for windows
>   build: add additional common files support
>   eal: add minimum viable code to support parsing
>
>  lib/librte_eal/common/eal_common_options.c    |  14 +
>  .../common/include/arch/x86/rte_vect.h        |   4 +-
>  lib/librte_eal/windows/eal/eal.c              | 194 ++++-
>  lib/librte_eal/windows/eal/eal_debug.c        |   1 +
>  lib/librte_eal/windows/eal/eal_lcore.c        |   3 +
>  lib/librte_eal/windows/eal/eal_thread.c       |  11 +
>  lib/librte_eal/windows/eal/getopt.c           | 470 +++++++++++++
>  lib/librte_eal/windows/eal/include/dirent.h   | 664 ++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h   |  92 +++
>  lib/librte_eal/windows/eal/include/pthread.h  |  66 ++
>  lib/librte_eal/windows/eal/include/rte_os.h   |  42 ++
>  lib/librte_eal/windows/eal/include/sched.h    |  46 ++
>  .../windows/eal/include/sys/queue.h           |   8 +
>  lib/librte_eal/windows/eal/meson.build        |   9 +-
>  license/exceptions.txt                        |  12 +-
>  15 files changed, 1625 insertions(+), 11 deletions(-)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by: Narcisa Ana Maria Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Ana Maria Vasile <Narcisa.Vasile@microsoft.com>



^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 1/9] license: add license exception for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows Pallavi Kadam
@ 2020-02-12  0:38                   ` " Narcisa Ana Maria Vasile
  2020-02-12 21:38                   ` [dpdk-dev] " Thomas Monjalon
  1 sibling, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:38 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> The Governing Board and Tech Board have provided exceptions for
> MIT and BSD-2-Clause license files for DPDK support on Windows.
>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> ---
>  license/exceptions.txt | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 2/9] eal: dirent.h implementation for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 2/9] eal: dirent.h implementation " Pallavi Kadam
@ 2020-02-12  0:40                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:40 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Adding dirent.h on Windows to support common code.
> eal_common_options.c includes this file.
>
> The original contribution is under MIT license.
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftronkko%2Fdirent&amp;data=02%7C01%7CNarcisa.Vasile%40microsoft.com%7C0bc1f84503194981e75f08d7ab7c1e5b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637166421901560917&amp;sdata=QhridVhRo5psnyCYGBzHDOHvhZ0JPLsoy5hJ1XA6SKU%3D&amp;reserved=0
>
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
>  lib/librte_eal/windows/eal/include/dirent.h | 664 ++++++++++++++++++++
>  1 file changed, 664 insertions(+)
>  create mode 100644 lib/librte_eal/windows/eal/include/dirent.h

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 3/9] eal: add additional function overrides in windows header files
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 3/9] eal: add additional function overrides in windows header files Pallavi Kadam
@ 2020-02-12  0:40                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:40 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Adding additional function definitions for pthread, cpuset
> implementation, asprintf implementation, in order to support
> common code.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
>  lib/librte_eal/windows/eal/include/pthread.h  | 66 +++++++++++++++++++
>  lib/librte_eal/windows/eal/include/rte_os.h   | 42 ++++++++++++
>  lib/librte_eal/windows/eal/include/sched.h    | 46 +++++++++++++
>  .../windows/eal/include/sys/queue.h           |  8 +++
>  4 files changed, 162 insertions(+)
>

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 4/9] eal: getopt implementation for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 4/9] eal: getopt implementation for windows Pallavi Kadam
@ 2020-02-12  0:41                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:41 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Adding getopt files to support parsing option on
> Windows.
>
> The original contribution is under BSD-2 license.
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgreenplum-db%2Flibusual%2Fblob%2Fmaster%2Fusual%2Fgetopt.c&amp;data=02%7C01%7CNarcisa.Vasile%40microsoft.com%7Cb0740364811e4d99d2e408d7ab7c2e37%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637166422146049654&amp;sdata=UkpRuUbgfTQXbnMKApxlZmtoOIOcPZrFN%2BnnZ%2B2CXmw%3D&amp;reserved=0
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgreenplum-db%2Flibusual%2Fblob%2Fmaster%2Fusual%2Fgetopt.h&amp;data=02%7C01%7CNarcisa.Vasile%40microsoft.com%7Cb0740364811e4d99d2e408d7ab7c2e37%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637166422146049654&amp;sdata=lGlLnaGZQ0beLe8ZweVZZVZDopib%2BDuWpAto2A1JkLc%3D&amp;reserved=0
>
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
>  lib/librte_eal/windows/eal/getopt.c         | 470 ++++++++++++++++++++
>  lib/librte_eal/windows/eal/include/getopt.h |  92 ++++
>  lib/librte_eal/windows/eal/meson.build      |   1 +
>  3 files changed, 563 insertions(+)
>  create mode 100644 lib/librte_eal/windows/eal/getopt.c
>  create mode 100644 lib/librte_eal/windows/eal/include/getopt.h
>
Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 5/9] eal: add function to detect process type
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 5/9] eal: add function to detect process type Pallavi Kadam
@ 2020-02-12  0:42                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:42 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Adding a function to detect process type, also included
> header files to contain suitable function declarations
> and to support extra warning flags.
>
> 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/windows/eal/eal.c        | 61 ++++++++++++++++++++++++-
>  lib/librte_eal/windows/eal/eal_debug.c  |  1 +
>  lib/librte_eal/windows/eal/eal_lcore.c  |  3 ++
>  lib/librte_eal/windows/eal/eal_thread.c | 11 +++++
>  4 files changed, 75 insertions(+), 1 deletion(-)
>
Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 6/9] eal: include SSE4 support for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 6/9] eal: include SSE4 support for windows Pallavi Kadam
@ 2020-02-12  0:42                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:42 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Modified \common\include\arch\x86\rte_vect.h
> to include SSE4 header for Windows.
>
> Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>
> ---
>  lib/librte_eal/common/include/arch/x86/rte_vect.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 7/9] eal: remove syslog and dlfcn support for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 7/9] eal: remove syslog and dlfcn " Pallavi Kadam
@ 2020-02-12  0:42                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:42 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Excluding syslog/ dlfcn definitions and parameters
> from Windows by adding #ifndef RTE_EXEC_ENV_WINDOWS.
>
> Note: This is a temporary change. In future, separate
> 'unix' directory will be created for unix specific functions.
>
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> ---
>  lib/librte_eal/common/eal_common_options.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 8/9] build: add additional common files support
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 8/9] build: add additional common files support Pallavi Kadam
@ 2020-02-12  0:42                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:42 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Added support for additional common files in meson build
> to expand Windows EAL and to support the lcore parsing
> feature on Windows.
>
> 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/windows/eal/meson.build | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v8 9/9] eal: add minimum viable code to support parsing
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 9/9] eal: add minimum viable code to support parsing Pallavi Kadam
@ 2020-02-12  0:43                   ` " Narcisa Ana Maria Vasile
  0 siblings, 0 replies; 149+ messages in thread
From: Narcisa Ana Maria Vasile @ 2020-02-12  0:43 UTC (permalink / raw)
  To: Pallavi Kadam, dev, thomas
  Cc: Harini Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

On 2/6/2020 7:14 PM, Pallavi Kadam wrote:
> Adding specific logic for eal.c to support parsing on
> Windows.
>
> 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/windows/eal/eal.c | 133 ++++++++++++++++++++++++++++++-
>  1 file changed, 130 insertions(+), 3 deletions(-)
>

Tested-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>

Acked-by: Narcisa Vasile <Narcisa.Vasile@microsoft.com>


^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows
  2020-02-07  3:14                 ` [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows Pallavi Kadam
  2020-02-12  0:38                   ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
@ 2020-02-12 21:38                   ` " Thomas Monjalon
  2020-02-12 21:55                     ` Ranjit Menon
  1 sibling, 1 reply; 149+ messages in thread
From: Thomas Monjalon @ 2020-02-12 21:38 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar

07/02/2020 04:14, Pallavi Kadam:
> The Governing Board and Tech Board have provided exceptions for
> MIT and BSD-2-Clause license files for DPDK support on Windows.
> 
> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> ---
> +---------------------------------------------------------------------------------------------------
> +1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
> +2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
> +3.ISC AND
> +  BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/getopt.c
> +---------------------------------------------------------------------------------------------------

I fixed the dates according to my records:
1.MIT               10/23/2019        02/10/2020        lib/librte_eal/windows/eal/include/dirent.h
2.BSD-2-Clause      10/23/2019        12/18/2019        lib/librte_eal/windows/eal/include/getopt.h
3.ISC AND
  BSD-2-Clause      10/23/2019        12/18/2019        lib/librte_eal/windows/eal/getopt.c





^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities
  2020-02-07 19:05                 ` [dpdk-dev] [PATCH v8 0/9] Windows patchset with additional EAL functionalities Dmitry Kozlyuk
@ 2020-02-12 21:52                   ` Thomas Monjalon
  0 siblings, 0 replies; 149+ messages in thread
From: Thomas Monjalon @ 2020-02-12 21:52 UTC (permalink / raw)
  To: Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, ranjit.menon, antara.ganesh.kolar,
	Dmitry Kozlyuk, narcisa.vasile, talshn

07/02/2020 20:05, Dmitry Kozlyuk:
> > This patchset includes additional functionalities for Windows EAL
> > to support command-line parsing feature and some EAL common code
> > on Windows.
> > 
> > This patchset can be applied to windpdk-next-dev branch in the draft repo.
> > 
> > v8 changes:
> > 	Fixed the naming conventions.
> > 	Fixed a crash encountered due to getopt function.
> > 	Removed "--syslog" from help options for Windows.
> > 
> 
> Observing no issues on Windows 10, Meson 0.53.999, Clang 9.0.1.
> 
> Reviewed-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

Applied, thanks



^ permalink raw reply	[flat|nested] 149+ messages in thread

* Re: [dpdk-dev] [PATCH v8 1/9] license: add license exception for windows
  2020-02-12 21:38                   ` [dpdk-dev] " Thomas Monjalon
@ 2020-02-12 21:55                     ` Ranjit Menon
  0 siblings, 0 replies; 149+ messages in thread
From: Ranjit Menon @ 2020-02-12 21:55 UTC (permalink / raw)
  To: Thomas Monjalon, Pallavi Kadam
  Cc: dev, Harini.Ramakrishnan, keith.wiles, bruce.richardson,
	david.marchand, jerinjacobk, antara.ganesh.kolar

On 2/12/2020 1:38 PM, Thomas Monjalon wrote:
> 07/02/2020 04:14, Pallavi Kadam:
>> The Governing Board and Tech Board have provided exceptions for
>> MIT and BSD-2-Clause license files for DPDK support on Windows.
>>
>> Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
>> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
>> ---
>> +---------------------------------------------------------------------------------------------------
>> +1.MIT               11/12/2019        11/12/2019        lib/librte_eal/windows/eal/include/dirent.h
>> +2.BSD-2-Clause      01/08/2020        01/08/2020        lib/librte_eal/windows/eal/include/getopt.h
>> +