From patchwork Tue Oct 22 20:02:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 61684 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 C106D1BF12; Tue, 22 Oct 2019 22:28:19 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id AF4C01BEDC for ; Tue, 22 Oct 2019 22:28:10 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2019 13:28:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,217,1569308400"; d="scan'208";a="397813836" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga005.fm.intel.com with ESMTP; 22 Oct 2019 13:28:09 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net, Harini.Ramakrishnan@microsoft.com Cc: keith.wiles@intel.com, bruce.richardson@intel.com, david.marchand@redhat.com, jerinjacobk@gmail.com, ranjit.menon@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Tue, 22 Oct 2019 13:02:21 -0700 Message-Id: <20191022200227.1920-4-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20191022200227.1920-1-pallavi.kadam@intel.com> References: <20190926202924.6876-1-pallavi.kadam@intel.com> <20191022200227.1920-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH v3 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. Modified \common\include\arch\x86\rte_vect.h to include SSE4 header for Windows. Signed-off-by: Antara Ganesh Kolar Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- .../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 #include "generic/rte_vect.h" -#if (defined(__ICC) || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) +#if (defined(__ICC) || \ + (defined(_WIN64)) || \ + (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) #include /* 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 + +#else /* NEED_USUAL_GETOPT */ + +/* All the headers include this file. */ +#include +#include +#include +#include +#include +#include + +#include + +/* 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_ */