From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 21107A0A0F; Thu, 8 Apr 2021 00:23:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFE49140FF9; Thu, 8 Apr 2021 00:23:03 +0200 (CEST) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by mails.dpdk.org (Postfix) with ESMTP id 9A7D7140FF1 for ; Thu, 8 Apr 2021 00:23:02 +0200 (CEST) Received: by mail-lj1-f175.google.com with SMTP id 15so22636356ljj.0 for ; Wed, 07 Apr 2021 15:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K78klqHtweHVbOWFUXs5vyOK2p/9L0MbERMSj1Op1RU=; b=hB2CqSq5f9ASMsQbGw96+fta55q0Q9krWzUjaVWwsp7d0qpnzVwm205Svk+3W3+2DN N8/hb15Ep/Ki+GCcfZ96CQOrwwBwvR+1Luaudh0QsnpkFEo8PpR9GTHA/FBCs69hpAwN wp8QWOJMhcFF4pGwSvwO/73b1sDAs/Jco8RWBDlRFaMzfaEQRUuC8dOH89u+BAgKQLOh BAUUlwvCZvihnf1q8l/BKTd1131me1cudsr0ihRI+pAT3v7Qem+E17FUXq7zGN7DcjNI linXIglCEvq+Z+VQ4SF/WJZ3NkrCUHQQOdXIntWnkEH7dSndmRMpYqRn8rwQhucVOhyI SFxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K78klqHtweHVbOWFUXs5vyOK2p/9L0MbERMSj1Op1RU=; b=mzPf0d44r8kkDev9t8/0ZG2zD72OoXn0wJny2+njFCO5lgz9Lv8SpV0u0ySqpOAruA T+qWNPdHhjO5yrC9lpBrOFKa2lF9wxqqCY0T+3brQ2ISKbpCrLZgec/MOF8y2+1WliGd /WlEb6lmLMyihXfUtijrDd2OA6lxzhHMvdwrzGKKZ6jdTW0a3IwoXoXdfCUgRqcIf00j R/u9MIGS63d3gdosa2t8TsicAtY2yw6LjNa7pjjk0Bfb+wHCiZGhs9TRicG2oGbDOe29 cmeP1ESm5j9GxfMnjemFz/x9vyF7hllXDP1+WPbZ/RX2ixqFv2ECefSoINc1GuBAs9xS 8tDQ== X-Gm-Message-State: AOAM530tO5Ax2OOxk35EjVFZ7taCspEZU2dk9wUzH4jStmSaT4WV1xx+ EcyrBqzI0WatNTIRbClHiMzC3HjYo76Xjz9g X-Google-Smtp-Source: ABdhPJxQmhsF9Xj+KXfTjZqBWHbauFCcystIBwK0zXfpy+rT/sYt8CBmAnuTpIiBdHqRbLSPQL7hpw== X-Received: by 2002:a2e:7d02:: with SMTP id y2mr3626820ljc.153.1617834181461; Wed, 07 Apr 2021 15:23:01 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id u27sm441965lfk.254.2021.04.07.15.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 15:23:00 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Jie Zhou , Nick Connolly , Dmitry Kozlyuk , Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko , Beilei Xing , Jeff Guo , Olivier Matz , Bruce Richardson , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Date: Thu, 8 Apr 2021 01:22:47 +0300 Message-Id: <20210407222249.6729-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210407222249.6729-1-dmitry.kozliuk@gmail.com> References: <20210403234129.20296-1-dmitry.kozliuk@gmail.com> <20210407222249.6729-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" DPDK code often relies on functions and macros that are not standard C, but are found on all platforms, even if by slightly different names. Windows provided macros or inline definitions for such symbols. However, when placed in public header, these symbols were unnecessarily exposed, breaking consumer POSIX compatibility code. Move most of the shims to , a header to be used instead of by internal code. Include it in libraries and PMDs that previously imported shims from . Directly replace shims that were only used inside EAL: * index -> strchr, rindex -> strrchr * sleep -> rte_delay_us_sleep * strerror_r -> strerror_s Signed-off-by: Dmitry Kozlyuk --- drivers/bus/pci/private.h | 4 +- drivers/bus/vdev/vdev_private.h | 2 + drivers/common/mlx5/mlx5_common.h | 1 + drivers/net/i40e/i40e_ethdev.c | 1 + lib/librte_cmdline/cmdline.c | 4 -- lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_private.h | 1 + lib/librte_cmdline/cmdline_socket.c | 4 -- lib/librte_eal/common/eal_common_config.c | 1 - lib/librte_eal/common/eal_common_errno.c | 4 ++ lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/common/eal_common_timer.c | 4 +- lib/librte_eal/common/eal_internal_cfg.h | 1 + lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++ lib/librte_eal/linux/include/rte_os_shim.h | 14 +++++ lib/librte_eal/windows/eal_hugepages.c | 1 - lib/librte_eal/windows/eal_lcore.c | 1 - lib/librte_eal/windows/eal_memalloc.c | 1 - lib/librte_eal/windows/include/rte_os.h | 62 ++------------------ lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++ lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_kvargs/rte_kvargs.c | 1 + 22 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index f566943f5e..4cd9d14ec7 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -7,8 +7,10 @@ #include #include -#include + #include +#include +#include extern struct rte_pci_bus rte_pci_bus; diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h index ba6dc48ff3..e683f5f133 100644 --- a/drivers/bus/vdev/vdev_private.h +++ b/drivers/bus/vdev/vdev_private.h @@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 8eda6749b4..211e330178 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "mlx5_prm.h" #include "mlx5_devx_cmds.h" diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index fcf150e127..cf9e996ca5 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "i40e_logs.h" #include "base/i40e_prototype.h" diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 79ea5f98c8..49770869bb 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -18,10 +18,6 @@ #include "cmdline_private.h" -#ifdef RTE_EXEC_ENV_WINDOWS -#define write _write -#endif - static void cmdline_valid_buffer(struct rdline *rdl, const char *buf, __rte_unused unsigned int size) diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c index e9585c9eea..73ed9ba290 100644 --- a/lib/librte_cmdline/cmdline_os_windows.c +++ b/lib/librte_cmdline/cmdline_os_windows.c @@ -4,8 +4,6 @@ #include -#include - #include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */ diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h index a8a6ee9e69..a87c45275c 100644 --- a/lib/librte_cmdline/cmdline_private.h +++ b/lib/librte_cmdline/cmdline_private.h @@ -8,6 +8,7 @@ #include #include +#include #ifdef RTE_EXEC_ENV_WINDOWS #include #endif diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c index 0fe1497008..998e8ade25 100644 --- a/lib/librte_cmdline/cmdline_socket.c +++ b/lib/librte_cmdline/cmdline_socket.c @@ -16,10 +16,6 @@ #include "cmdline_private.h" #include "cmdline_socket.h" -#ifdef RTE_EXEC_ENV_WINDOWS -#define open _open -#endif - struct cmdline * cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path) { diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c index 56d09dda7f..1c4c4dd585 100644 --- a/lib/librte_eal/common/eal_common_config.c +++ b/lib/librte_eal/common/eal_common_config.c @@ -3,7 +3,6 @@ */ #include -#include #include #include "eal_private.h" diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c index 2a10fb823f..f86802705a 100644 --- a/lib/librte_eal/common/eal_common_errno.c +++ b/lib/librte_eal/common/eal_common_errno.c @@ -15,6 +15,10 @@ #include #include +#ifdef RTE_EXEC_ENV_WINDOWS +#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum) +#endif + RTE_DEFINE_PER_LCORE(int, _rte_errno); const char * diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 622c7bc429..28da464fc9 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1936,7 +1936,7 @@ eal_check_common_options(struct internal_config *internal_cfg) RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n"); return -1; } - if (index(eal_get_hugefile_prefix(), '%') != NULL) { + if (strchr(eal_get_hugefile_prefix(), '%') != NULL) { RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" " "option\n"); return -1; diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 71e0bd035a..86f8429847 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -47,9 +47,9 @@ estimate_tsc_freq(void) #define CYC_PER_10MHZ 1E7 RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly" " - clock timings may be less accurate.\n"); - /* assume that the sleep(1) will sleep for 1 second */ + /* assume that the rte_delay_us_sleep() will sleep for 1 second */ uint64_t start = rte_rdtsc(); - sleep(1); + rte_delay_us_sleep(US_PER_S); /* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ); } diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h index 51dbe86e2b..d6c0470eb8 100644 --- a/lib/librte_eal/common/eal_internal_cfg.h +++ b/lib/librte_eal/common/eal_internal_cfg.h @@ -11,6 +11,7 @@ #define EAL_INTERNAL_CFG_H #include +#include #include #include "eal_thread.h" diff --git a/lib/librte_eal/freebsd/include/rte_os_shim.h b/lib/librte_eal/freebsd/include/rte_os_shim.h new file mode 100644 index 0000000000..1e85229ca9 --- /dev/null +++ b/lib/librte_eal/freebsd/include/rte_os_shim.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include + +/** + * @file + * @internal + * Provides semi-standard OS facilities by convenient names. + */ + +#endif /* _RTE_OS_SHIM_ */ diff --git a/lib/librte_eal/linux/include/rte_os_shim.h b/lib/librte_eal/linux/include/rte_os_shim.h new file mode 100644 index 0000000000..1e85229ca9 --- /dev/null +++ b/lib/librte_eal/linux/include/rte_os_shim.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include + +/** + * @file + * @internal + * Provides semi-standard OS facilities by convenient names. + */ + +#endif /* _RTE_OS_SHIM_ */ diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c index 83a3d0ffc6..b007dceb39 100644 --- a/lib/librte_eal/windows/eal_hugepages.c +++ b/lib/librte_eal/windows/eal_hugepages.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "eal_private.h" #include "eal_filesystem.h" diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c index a85149be95..476c2d2bdf 100644 --- a/lib/librte_eal/windows/eal_lcore.c +++ b/lib/librte_eal/windows/eal_lcore.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "eal_private.h" #include "eal_thread.h" diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c index 85a9712cea..4459d59b1a 100644 --- a/lib/librte_eal/windows/eal_memalloc.c +++ b/lib/librte_eal/windows/eal_memalloc.c @@ -3,7 +3,6 @@ */ #include -#include #include "eal_internal_cfg.h" #include "eal_memalloc.h" diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h index 1afe49f35e..66c711d458 100644 --- a/lib/librte_eal/windows/include/rte_os.h +++ b/lib/librte_eal/windows/include/rte_os.h @@ -18,72 +18,18 @@ extern "C" { #endif -/* limits.h replacement, value as in */ -#ifndef PATH_MAX -#define PATH_MAX _MAX_PATH -#endif - -#ifndef sleep -#define sleep(x) Sleep(1000 * (x)) -#endif - -#ifndef strerror_r -#define strerror_r(a, b, c) strerror_s(b, c, a) -#endif - -#ifndef strdup -/* strdup is deprecated in Microsoft libc and _strdup is preferred */ -#define strdup(str) _strdup(str) -#endif - -#ifndef strtok_r -#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr) -#endif - -#ifndef index -#define index(a, b) strchr(a, b) -#endif - -#ifndef rindex -#define rindex(a, b) strrchr(a, b) -#endif - -#ifndef strncasecmp -#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count) -#endif - -#ifndef close -#define close _close -#endif - -#ifndef unlink -#define unlink _unlink -#endif - /* 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) -/* as in */ +/* This is an exception without "rte_" prefix, because Windows does have + * ssize_t, but it's defined in which we avoid to expose. + * If ssize_t is defined in user code, it necessarily has the same type. + */ typedef long long ssize_t; -#ifndef RTE_TOOLCHAIN_GCC -static inline const char * -eal_strerror(int code) -{ - static char buffer[128]; - - strerror_s(buffer, sizeof(buffer), code); - return buffer; -} - -#ifndef strerror -#define strerror eal_strerror -#endif -#endif /* RTE_TOOLCHAIN_GCC */ - #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h new file mode 100644 index 0000000000..edd9a1082c --- /dev/null +++ b/lib/librte_eal/windows/include/rte_os_shim.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include + +/** + * @file + * @internal + * Provides semi-standard OS facilities by convenient names. + */ + +#ifndef PATH_MAX +#define PATH_MAX _MAX_PATH +#endif + +#define strdup(str) _strdup(str) +#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr) +#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count) + +#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__) +#define read(fd, buf, n) _read(fd, buf, n) +#define write(fd, buf, n) _write(fd, buf, n) +#define close(fd) _close(fd) +#define unlink(path) _unlink(path) + +#endif /* _RTE_OS_SHIM_ */ diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h index 220ddd4408..9bb0879538 100644 --- a/lib/librte_ethdev/ethdev_private.h +++ b/lib/librte_ethdev/ethdev_private.h @@ -5,6 +5,8 @@ #ifndef _ETH_PRIVATE_H_ #define _ETH_PRIVATE_H_ +#include + #include "rte_ethdev.h" #ifdef __cplusplus diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index ffae8914cf..4c1f7dc2c1 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -7,6 +7,7 @@ #include #include +#include #include #include "rte_kvargs.h" -- 2.29.3