From patchwork Mon Sep 9 19:53:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59045 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8AC201EC65; Mon, 9 Sep 2019 22:18:51 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 89DAE1C07B for ; Mon, 9 Sep 2019 22:18:48 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086184" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:46 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:53:56 -0700 Message-Id: <20190909195404.4760-2-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 1/9] eal: eal stub to support parsing feature on windows X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding initial stub to support command line parsing for lcore mask option on Windows. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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; +} From patchwork Mon Sep 9 19:53:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59046 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 752DE1ECA5; Mon, 9 Sep 2019 22:18:54 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 63FB52B96 for ; Mon, 9 Sep 2019 22:18:48 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086188" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:46 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:53:57 -0700 Message-Id: <20190909195404.4760-3-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 2/9] eal: syslog implementation for windows X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding syslog.h on Windows for supporting common code. This implementation has BSD-3-Clause licensing. Signed-off-by: Antara Ganesh Kolar Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 + +/* + * 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 "[:]". The + * may be a numeric port or it may be a name of a service. + * If the 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 */ From patchwork Mon Sep 9 19:53:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59047 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7BC271ECD5; Mon, 9 Sep 2019 22:18:57 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 30E102B96 for ; Mon, 9 Sep 2019 22:18:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086191" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:46 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:53:58 -0700 Message-Id: <20190909195404.4760-4-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 3/9] eal: add windows compatible header files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding 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 Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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" From patchwork Mon Sep 9 19:53:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59049 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BC74C1ED56; Mon, 9 Sep 2019 22:19:02 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 429A71EC32 for ; Mon, 9 Sep 2019 22:18:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086195" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:47 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:53:59 -0700 Message-Id: <20190909195404.4760-5-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 4/9] eal: dirent.h implementation for windows X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding dirent.h on Windows to support common code. The original contribution is under MIT license. Signed-off-by: Antara Ganesh Kolar Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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*/ From patchwork Mon Sep 9 19:54:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59048 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4334D1ED19; Mon, 9 Sep 2019 22:19:00 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id DA2C41EC41 for ; Mon, 9 Sep 2019 22:18:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086198" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:47 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:54:00 -0700 Message-Id: <20190909195404.4760-6-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 5/9] eal: add additional function overrides in windows header files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding additional function definitions for pthread, cpuset implementation, asprintf implementation, in order to support common code. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 + +#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 #include #include +#include + +/* limits.h replacement */ +#include +#ifndef PATH_MAX +#define PATH_MAX _MAX_PATH +#endif #define strerror_r(a, b, c) strerror_s(b, c, a) @@ -28,6 +35,11 @@ typedef SSIZE_T ssize_t; #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr) +#define index(a, b) strchr(a, b) +#define rindex(a, b) strrchr(a, b) + +#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count) + /** * Create a thread. * This function is private to EAL. @@ -45,6 +57,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 From patchwork Mon Sep 9 19:54:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59050 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 235791ED6B; Mon, 9 Sep 2019 22:19:05 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 14DB71EC4E for ; Mon, 9 Sep 2019 22:18:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086201" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:47 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:54:01 -0700 Message-Id: <20190909195404.4760-7-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 6/9] eal: getopt implementation for windows X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding 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 Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +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' ) From patchwork Mon Sep 9 19:54:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59052 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6D5841ED99; Mon, 9 Sep 2019 22:19:10 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 801F51EC61 for ; Mon, 9 Sep 2019 22:18:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086204" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:48 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:54:02 -0700 Message-Id: <20190909195404.4760-8-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 7/9] eal: add function to detect process type X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding a function to detect process type and include header files to contain suitable function declarations. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 #include #include #include #include +#include #include #include #include +#include +#include #include +/* 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 #include #include +#include #include 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 From patchwork Mon Sep 9 19:54:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59051 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0C4851ED81; Mon, 9 Sep 2019 22:19:08 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id B4F2B1EC41 for ; Mon, 9 Sep 2019 22:18:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086207" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:48 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:54:03 -0700 Message-Id: <20190909195404.4760-9-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 8/9] build: add additional common files support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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', From patchwork Mon Sep 9 19:54:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 59053 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 318391EDD6; Mon, 9 Sep 2019 22:19:14 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 02C0A1EC32 for ; Mon, 9 Sep 2019 22:18:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 13:18:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,487,1559545200"; d="scan'208";a="385086210" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga006.fm.intel.com with ESMTP; 09 Sep 2019 13:18:48 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Mon, 9 Sep 2019 12:54:04 -0700 Message-Id: <20190909195404.4760-10-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190909195404.4760-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> <20190909195404.4760-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding specific logic for eal.c to support parsing on Windows. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- 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 #include #include +#include #include + /* 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