eal/windows: do not expose POSIX symbols
Subsystems (2)
cover eal/windows: do not expose POSIX symbols
On Windows, rte_os.h contains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general.
First define required wrappers, then fix POSIX dependencies in Windows-enabled libraries and drivers, then eliminate POSIX symbols from Windows EAL API. Commits are arranged so that they all compile and are limited in scope; patches 5, 6, 7 can be squashed if needed.
No "Fixes" tags, because it's really an enhancement, preventing issues rather then solving direct ones.
Dmitry Kozlyuk (7):
eal: add wrappers for POSIX string functions
eal: add macro for maximum path length
eal: add sleep API
eal: add asprintf() internal wrapper
lib: remove POSIX dependencies
drivers: remove POSIX dependencies
eal/windows: do not expose POSIX symbols
doc/guides/rel_notes/release_21_05.rst | 9 ++ drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +- drivers/net/i40e/i40e_ethdev.c | 56 +++++------ lib/librte_cmdline/cmdline.c | 1 + lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 6 +- lib/librte_eal/common/eal_common_devargs.c | 7 +- lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_fbarray.c | 8 +- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_log.c | 5 +- lib/librte_eal/common/eal_common_options.c | 42 ++++---- lib/librte_eal/common/eal_common_timer.c | 5 +- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 4 +- .../common/eal_common_trace_utils.c | 13 +-- lib/librte_eal/common/eal_filesystem.h | 8 +- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_private.h | 23 +++++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 6 +- lib/librte_eal/include/rte_string_fns.h | 42 ++++++++ lib/librte_eal/include/rte_thread.h | 11 +++ lib/librte_eal/linux/include/rte_os.h | 6 +- lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 6 ++ lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 ++++++ lib/librte_eal/windows/eal_thread.c | 9 +- lib/librte_eal/windows/include/dirent.h | 21 ++-- lib/librte_eal/windows/include/rte_os.h | 99 ++----------------- lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++-- 38 files changed, 266 insertions(+), 206 deletions(-)
Signature · 1 line
2.29.2
PATCH 1/7 eal: add wrappers for POSIX string functions
POSIX strncasecmp(), strdup(), and strtok_r() have different names on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
Add wrappers as inline functions, because they're used from librte_kvargs, and thus cannot be in librte_eal; besides, implementation is trivial.
--- lib/librte_eal/common/eal_common_dev.c | 6 +-- lib/librte_eal/common/eal_common_devargs.c | 7 ++-- lib/librte_eal/common/eal_common_log.c | 5 ++- lib/librte_eal/common/eal_common_options.c | 12 +++--- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/include/rte_string_fns.h | 42 +++++++++++++++++++ 7 files changed, 60 insertions(+), 16 deletions(-)
lib/librte_eal/common/eal_common_dev.c +3 -3
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,if (!device_name) { event_cb->dev_name =NULL ; }else { - event_cb->dev_name =strdup (device_name); + event_cb->dev_name =rte_strdup (device_name);if (event_cb->dev_name ==NULL ) { ret = -ENOMEM ; goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str) end =strcspn (str,",/" );if (str[end] ==',' ) { - copy =strdup (&str[end +1 ]); + copy =rte_strdup (&str[end +1 ]); }else {/* '/' or '\0' */ - copy =strdup ("" ); + copy =rte_strdup ("" ); }if (copy ==NULL ) { rte_errno =ENOMEM ;
lib/librte_eal/common/eal_common_devargs.c +4 -3
@@ -18,6 +18,7 @@#include <rte_errno.h> #include <rte_kvargs.h> #include <rte_log.h> +#include <rte_string_fns.h> #include <rte_tailq.h> #include "eal_private.h"
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,* anything and keep referring only to it. */ if (devargs->data != devstr) { - devargs->data =strdup (devstr); + devargs->data =rte_strdup (devstr);if (devargs->data ==NULL ) {RTE_LOG (ERR ,EAL ,"OOM\n" ); ret = -ENOMEM ;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev) da->bus = bus;/* Parse eventual device arguments */ if (devname[i] ==',' ) - da->args =strdup (&devname[i +1 ]); + da->args =rte_strdup (&devname[i +1 ]);else - da->args =strdup ("" ); + da->args =rte_strdup ("" );if (da->args ==NULL ) {RTE_LOG (ERR ,EAL ,"not enough memory to parse arguments\n" );return -ENOMEM ;
lib/librte_eal/common/eal_common_log.c +3 -2
@@ -14,6 +14,7 @@#include <rte_eal.h> #include <rte_log.h> #include <rte_per_lcore.h> +#include <rte_string_fns.h> #include "eal_private.h"
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,if (regcomp (&opt_ll->re_match, regex,0 ) !=0 ) goto fail; }else if (pattern) { - opt_ll->pattern =strdup (pattern); + opt_ll->pattern =rte_strdup (pattern);if (opt_ll->pattern ==NULL ) goto fail; }else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)static int __rte_log_register (const char *name,int id) { -char *dup_name =strdup (name); +char *dup_name =rte_strdup (name);if (dup_name ==NULL )return -ENOMEM ;
lib/librte_eal/common/eal_common_options.c +6 -6
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (i =0 ; i < argc; i++) { - eal_args[i] =strdup (argv[i]); + eal_args[i] =rte_strdup (argv[i]);if (strcmp (argv[i],"--" ) ==0 )break ; }
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (j =0 ; i < argc; j++, i++) - eal_app_args[j] =strdup (argv[i]); + eal_app_args[j] =rte_strdup (argv[i]); eal_app_args[j] =NULL ;return 0 ;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)char *str, *level;int priority; - str =strdup (arg); + str =rte_strdup (arg);if (str ==NULL )return -1 ;
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)static enum rte_proc_type_t eal_parse_proc_type (const char *arg) { -if (strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 ) +if (rte_strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 )return RTE_PROC_PRIMARY ; -if (strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 ) +if (rte_strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 )return RTE_PROC_SECONDARY ; -if (strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 ) +if (rte_strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 )return RTE_PROC_AUTO ;return RTE_PROC_INVALID ;
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)if (strstr (field,"." ) ==NULL &&strstr (field,"->" ) ==NULL )return NULL ; - out =strdup (field); + out =rte_strdup (field);if (out ==NULL )return NULL ; p = out;
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)return -ENOMEM ; } - arg->val =strdup (val); + arg->val =rte_strdup (val);if (arg->val ==NULL ) {trace_err ("failed to allocate memory for %s" , val);free (arg);
lib/librte_eal/include/rte_string_fns.h +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 2/7 eal: add macro for maximum path length
In reply to Dmitry KozlyukPath length limit is PATH_MAX on Unix and _MAX_PATH on Windows. Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX in "common" multiprocess code, because it's really Unix-specific.
---PATH_MAX is not removed until the last patch to keep PCI building.
lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 8 +++---- lib/librte_eal/common/eal_common_options.c | 20 +++++++++--------- .../common/eal_common_trace_utils.c | 9 ++++---- lib/librte_eal/common/eal_filesystem.h | 8 +++---- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 2 ++ lib/librte_eal/linux/include/rte_os.h | 2 ++ lib/librte_eal/windows/include/dirent.h | 21 +++++++------------ lib/librte_eal/windows/include/rte_os.h | 2 ++ 12 files changed, 41 insertions(+), 39 deletions(-)
lib/librte_eal/common/eal_common_config.c +1 -1
@@ -18,7 +18,7 @@ static struct rte_config rte_config = { };/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX ]; +static char runtime_dir[RTE_PATH_MAX ];/* internal configuration */ static struct internal_config internal_config;
lib/librte_eal/common/eal_common_fbarray.c +4 -4
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)static int resize_and_map (int fd,void *addr,size_t len) { -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *map_addr;if (eal_file_truncate (fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz) {size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];struct used_mask *msk;struct mem_area *ma =NULL ;void *data =NULL ;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr) {struct mem_area *ma =NULL , *tmp =NULL ;size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *data =NULL ;int fd =-1 ;
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)struct mem_area *tmp =NULL ;size_t mmap_len;int fd, ret; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];const struct internal_config *internal_conf =eal_get_internal_configuration ();
lib/librte_eal/common/eal_common_options.c +10 -10
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);struct shared_driver {TAILQ_ENTRY (shared_driver) next; -char name[PATH_MAX ]; +char name[RTE_PATH_MAX ];void * lib_handle; };
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)return -1 ; }memset (solib,0 ,sizeof (*solib)); -strlcpy (solib->name, path,PATH_MAX ); +strlcpy (solib->name, path,RTE_PATH_MAX );TAILQ_INSERT_TAIL (&solib_list, solib, next);return 0 ;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path) {DIR *d =NULL ;struct dirent *dent =NULL ; -char sopath[PATH_MAX ]; +char sopath[RTE_PATH_MAX ];if (path ==NULL || *path =='\0' )return 0 ;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)/* if not root, check down one level first */ if (strcmp (dirpath,"/" ) !=0 ) { -static __threadchar last_dir_checked[PATH_MAX ]; -char copy[PATH_MAX ]; +static __threadchar last_dir_checked[RTE_PATH_MAX ]; +char copy[RTE_PATH_MAX ];const char *dir; -strlcpy (copy, dirpath,PATH_MAX ); +strlcpy (copy, dirpath,RTE_PATH_MAX ); dir =dirname (copy); -if (strncmp (dir, last_dir_checked,PATH_MAX ) !=0 ) { +if (strncmp (dir, last_dir_checked,RTE_PATH_MAX ) !=0 ) {if (verify_perms (dir) !=0 )return -1 ; -strlcpy (last_dir_checked, dir,PATH_MAX ); +strlcpy (last_dir_checked, dir,RTE_PATH_MAX ); } }
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname) pathname, strerror(errno)); goto out; } -if (strnlen (realp,PATH_MAX ) ==PATH_MAX ) { -RTE_LOG (ERR ,EAL ,"Error, driver path greater than PATH_MAX\n" ); +if (strnlen (realp,RTE_PATH_MAX ) ==RTE_PATH_MAX ) { +RTE_LOG (ERR ,EAL ,"Error, driver path greater than RTE_PATH_MAX\n" ); goto out; }
lib/librte_eal/common/eal_common_trace_utils.c +5 -4
@@ -369,11 +369,11 @@ trace_mkdir(void)static int trace_meta_save (struct trace *trace) { -char file_name[PATH_MAX ]; +char file_name[RTE_PATH_MAX ];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/metadata" , trace->dir); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/metadata" , trace->dir);if (rc <0 )return rc;
@@ -400,11 +400,12 @@ static int trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr, uint32_t cnt) { - char file_name[PATH_MAX]; + char file_name[RTE_PATH_MAX];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/channel0_%d" , trace->dir, cnt); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/channel0_%d" , + trace->dir, cnt);if (rc <0 )return rc;
lib/librte_eal/common/eal_filesystem.h +4 -4
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);static inline const char *eal_runtime_config_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),RUNTIME_CONFIG_FNAME );
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)static inline const char *eal_mp_socket_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),MP_SOCKET_FNAME );
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {static inline const char *eal_hugepage_info_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_INFO_FNAME );
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)static inline const char *eal_hugepage_data_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_DATA_FNAME );
lib/librte_eal/common/eal_hugepages.h +1 -1
@@ -9,7 +9,7 @@#include <stdint.h> #include <limits.h> -#define MAX_HUGEPAGE_PATH PATH_MAX +#define MAX_HUGEPAGE_PATH RTE_PATH_MAX/** * Structure used to store information about hugepages that we mapped
lib/librte_eal/common/eal_internal_cfg.h +1 -1
@@ -27,7 +27,7 @@*/ struct hugepage_info {uint64_t hugepage_sz;/**< size of a huge page */ -char hugedir[PATH_MAX ];/**< dir where hugetlbfs is mounted */ +char hugedir[RTE_PATH_MAX ];/**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES ];/**< number of hugepages of that size on each socket */ int lock_descriptor;/**< file descriptor for hugepage dir */
lib/librte_eal/common/eal_trace.h +1 -1
@@ -51,7 +51,7 @@ struct trace_arg { };struct trace { -char dir[PATH_MAX ]; +char dir[RTE_PATH_MAX ];int dir_offset;int register_errno;bool status;
lib/librte_eal/freebsd/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <pthread_np.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpuset_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) do \ { \
lib/librte_eal/linux/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <sched.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpu_set_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) CPU_AND(dst, src1, src2)#define RTE_CPU_OR (dst, src1, src2) CPU_OR(dst, src1, src2)
lib/librte_eal/windows/include/dirent.h +8 -13
@@ -28,11 +28,6 @@#include <sys/stat.h> #include <errno.h> -/* Maximum length of file name */ -#if !defined(PATH_MAX ) -# define PATH_MAX MAX_PATH -#endif -/* File type flags for d_type */ #define DT_UNKNOWN 0#define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {int d_type;/* File name */ -wchar_t d_name[PATH_MAX ]; +wchar_t d_name[RTE_PATH_MAX ]; };typedef struct _wdirent _wdirent ;
@@ -113,7 +108,7 @@ struct dirent {int d_type;/* File name */ -char d_name[PATH_MAX ]; +char d_name[RTE_PATH_MAX ]; };typedef struct dirent dirent ;
@@ -388,12 +383,12 @@ opendir(const char *dirname)/* Allocate memory for DIR structure */ dirp = (DIR *)malloc (sizeof (struct DIR ));if (dirp) { -wchar_t wname[PATH_MAX ]; +wchar_t wname[RTE_PATH_MAX ];size_t n;/* Convert directory name to wide-character string */ - error =dirent_mbstowcs_s (&n, wname,PATH_MAX , - dirname,PATH_MAX ); + error =dirent_mbstowcs_s (&n, wname,RTE_PATH_MAX , + dirname,RTE_PATH_MAX );if (!error) {/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)/* Attempt to convert file name to multi-byte string */ error =dirent_wcstombs_s (&n, dirp->ent.d_name, -PATH_MAX , datap->cFileName,PATH_MAX ); +RTE_PATH_MAX , datap->cFileName,RTE_PATH_MAX );/* * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)*/ if (error && datap->cAlternateFileName[0 ] !='\0' ) { error =dirent_wcstombs_s ( - &n, dirp->ent.d_name,PATH_MAX , - datap->cAlternateFileName,PATH_MAX ); + &n, dirp->ent.d_name,RTE_PATH_MAX , + datap->cAlternateFileName,RTE_PATH_MAX ); }if (!error) {
lib/librte_eal/windows/include/rte_os.h +2 -0
@@ -20,6 +20,8 @@extern "C" {#endif +#define RTE_PATH_MAX _MAX_PATH +/* limits.h replacement, value as in <windows.h> */ #ifndef PATH_MAX #define PATH_MAX _MAX_PATH
Signature · 1 line
2.29.2
PATCH 3/7 eal: add sleep API
In reply to Dmitry KozlyukPOSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 6 ++++++ lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 33 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +6 -0
@@ -84,3 +84,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +3 -0
@@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL {
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.2
PATCH 4/7 eal: add asprintf() internal wrapper
In reply to Dmitry KozlyukPOSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().
--- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 8 ++--- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++ 7 files changed, 56 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +1 -1
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback =calloc (1 ,sizeof (*callback));if (callback ==NULL )return NULL ; -if (asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) { +if (eal_asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) {free (callback);return NULL ; }
lib/librte_eal/common/eal_common_options.c +4 -4
@@ -1435,7 +1435,7 @@ available_cores(void)return NULL ;/* first sequence */ -if (asprintf (&str,"%d" , idx) <0 ) +if (eal_asprintf (&str,"%d" , idx) <0 )return NULL ; previous = idx; sequence =0 ;
@@ -1452,7 +1452,7 @@ available_cores(void)/* finish current sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
@@ -1461,7 +1461,7 @@ available_cores(void) }/* new sequence */ -if (asprintf (&tmp,"%s,%d" , str, idx) <0 ) { +if (eal_asprintf (&tmp,"%s,%d" , str, idx) <0 ) {free (str);return NULL ; }
@@ -1473,7 +1473,7 @@ available_cores(void)/* finish last sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
lib/librte_eal/common/eal_common_trace.c +1 -1
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) fixup =trace_metadata_fixup_field (in);if (fixup !=NULL ) in = fixup; - rc =asprintf (&field,"%s %s %s;\n" , + rc =eal_asprintf (&field,"%s %s %s;\n" ,RTE_PER_LCORE (ctf_field) !=NULL ?RTE_PER_LCORE (ctf_field) :"" , datatype, in);
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)for (i =0 ; i <RTE_DIM (ctf_reserved_words); i++) {if (strcmp (field, ctf_reserved_words[i]) !=0 )continue ; -if (asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) +if (eal_asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) out =NULL ;return out; }
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)return -ENAMETOOLONG ; } -if (asprintf (&dir_path,"%s/" , val) ==-1 ) { +if (eal_asprintf (&dir_path,"%s/" , val) ==-1 ) {trace_err ("failed to copy directory: %s" ,strerror (errno));return -ENOMEM ; }
lib/librte_eal/common/eal_private.h +18 -0
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* Allocate a buffer large enough to hold the formatted string +* and perform formatting, equivalent to Unix asprintf(3). +* +* @param buffer +* Receives a pointer to allocated memory, call free(buffer) to deallocate. +* @param format +* Format string. +* @return +* Number of bytes allocated on success, (-1) on failure. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); +#else +#define eal_asprintf asprintf +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.2
PATCH 5/7 lib: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().
Locally rename Windows _close() to standard close().
--- lib/librte_cmdline/cmdline.c | 1 + lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++++++++++------- 4 files changed, 13 insertions(+), 9 deletions(-)
lib/librte_cmdline/cmdline.c +1 -0
@@ -19,6 +19,7 @@#include "cmdline_private.h" #ifdef RTE_EXEC_ENV_WINDOWS +#define close _close#define write _write#endif
lib/librte_ethdev/rte_class_eth.c +1 -1
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,return -1 ;/* not a representor port */ /* Parse devargs representor values. */ - values =strdup (value); + values =rte_strdup (value);if (values ==NULL )return -1 ;memset (&representors,0 ,sizeof (representors));
lib/librte_ethdev/rte_ethdev.c +1 -1
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)struct rte_kvargs_pair *pair;char *letter; - arglist->str =strdup (str_in); + arglist->str =rte_strdup (str_in);if (arglist->str ==NULL )return -ENOMEM ;
lib/librte_kvargs/rte_kvargs.c +10 -7
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)/* Copy the const char *params to a modifiable string * to pass to rte_strsplit */ - kvlist->str =strdup (params); + kvlist->str =rte_strdup (params);if (kvlist->str ==NULL )return -1 ;/* browse each key/value pair and add it in kvlist */ str = kvlist->str; -while ((str =strtok_r (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { +while ((str =rte_strtok (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { i = kvlist->count;if (i >=RTE_KVARGS_MAX )return -1 ; - kvlist->pairs[i].key =strtok_r (str,RTE_KVARGS_KV_DELIM , &ctx2); - kvlist->pairs[i].value =strtok_r (NULL ,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].key =rte_strtok ( + str,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].value =rte_strtok ( +NULL ,RTE_KVARGS_KV_DELIM , &ctx2);if (kvlist->pairs[i].key ==NULL || kvlist->pairs[i].value ==NULL )return -1 ;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)if (str[0 ] =='[' ) {/* Find the end of the list. */ while (str[strlen (str) -1 ] !=']' ) { -/* Restore the comma erased by strtok_r(). */ +/* Restore the comma erased by rte_strtok(). */ if (ctx1 ==NULL || ctx1[0 ] =='\0' )return -1 ;/* no closing bracket */ str[strlen (str)] =',' ;/* Parse until next comma. */ - str =strtok_r (NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1); + str =rte_strtok ( +NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1);if (str ==NULL )return -1 ;/* no closing bracket */ }
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],if (valid_ends ==NULL )return rte_kvargs_parse (args, valid_keys); - copy =strdup (args); + copy =rte_strdup (args);if (copy ==NULL )return NULL ;
Signature · 1 line
2.29.2
PATCH 6/7 drivers: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strncasecmp() with EAL rte_strncasecmp(). Replace POSIX strtok_r() with EAL rte_strtok(). Replace POSIX strdup() with EAL rte_strdup().
---
i40e: checkpatches.sh complains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.
drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +- drivers/net/i40e/i40e_ethdev.c | 56 +++++++++++++-------------- 5 files changed, 35 insertions(+), 34 deletions(-)
drivers/bus/pci/private.h +1 -1
@@ -92,7 +92,7 @@ struct mapped_pci_resource {TAILQ_ENTRY (mapped_pci_resource) next;struct rte_pci_addr pci_addr; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];int nb_maps;struct pci_map maps[PCI_MAX_RESOURCE ];struct pci_msix_table msix_table;
drivers/bus/vdev/vdev.c +2 -2
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args) devargs->bus = &rte_vdev_bus;if (args) - devargs->args =strdup (args); + devargs->args =rte_strdup (args);else - devargs->args =strdup ("" ); + devargs->args =rte_strdup ("" ); ret =strlcpy (devargs->name, name,sizeof (devargs->name));if (ret <0 || ret >= (int )sizeof (devargs->name)) {
drivers/bus/vdev/vdev_params.c +2 -1
@@ -8,6 +8,7 @@#include <rte_bus.h> #include <rte_kvargs.h> #include <rte_errno.h> +#include <rte_string_fns.h> #include "vdev_logs.h" #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,char *name;/* cannot pass const dev->name to rte_kvargs_process() */ - name =strdup (dev->name); + name =rte_strdup (dev->name);if (name ==NULL )return -1 ; ret = rte_kvargs_process(kvlist,
drivers/common/mlx5/mlx5_common_pci.c +2 -2
@@ -88,7 +88,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,return *ret; } nstr_org = nstr; - found =strtok_r (nstr,":" , &refstr); + found =rte_strtok (nstr,":" , &refstr);if (!found) goto err; do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key, goto err; } *ret |= class_val; - found =strtok_r (NULL ,":" , &refstr); + found =rte_strtok (NULL ,":" , &refstr); }while (found); err:free (nstr_org);
drivers/net/i40e/i40e_ethdev.c +28 -28
138 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 7/7 eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukExposing POSIX symbols could break consumer POSIX compatibility code.
* Make renaming of close() and unlink() private to EAL.
* Remove renaming of strncasecmp(), strtok_r(), and sleep() in favor of using EAL wrappers. Similarly remove PATH_MAX macro.
* Replace index(3p), which is not available on Windows, with strchr(3), as recommended by POSIX.1-2008. strerror_r() is only used inside EAL, rename it only where it's needed. Same for asprintf(), it has an internal EAL wrapper and is removed from public API.
--- doc/guides/rel_notes/release_21_05.rst | 9 ++ lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/common/eal_private.h | 5 ++ lib/librte_eal/freebsd/include/rte_os.h | 4 +- lib/librte_eal/linux/include/rte_os.h | 4 +- lib/librte_eal/windows/include/rte_os.h | 99 ++-------------------- 7 files changed, 29 insertions(+), 98 deletions(-)
doc/guides/rel_notes/release_21_05.rst +9 -0
@@ -84,6 +84,15 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols + has been incorrect and could conflict with consumer POSIX implementations. + Wrappers are provided for + ``strtok_r(3p)`` (``rte_strtok``), + ``strncasecmp(3p)`` (``rte_strncasecmp``), + ``sleep(3p)`` (``rte_thread_sleep``), + ``PATH_MAX`` (``RTE_PATH_MAX``). + Removed are ``strerror_r(3p)`` and ``asprintf(3p)``. + ABI Changes -----------
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#ifdef RTE_EXEC_ENV_WINDOWS +#define strerror_r (a, b, c) strerror_s(b, c, a) +#endif +RTE_DEFINE_PER_LCORE (int, _rte_errno); const char *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_private.h +5 -0
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);#define eal_asprintf asprintf#endif +#ifdef RTE_EXEC_ENV_WINDOWS +#define close _close +#define unlink _unlink +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/freebsd/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* freebsd OS. Functions will be added in future releases. +* freebsd OS. It must not define symbols without "rte_" prefix. */ #include <pthread_np.h>
lib/librte_eal/linux/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* linux OS. Functions will be added in future releases. +* linux OS. It must not define symbols without "rte_" prefix. */ #include <sched.h>
lib/librte_eal/windows/include/rte_os.h +6 -93
122 lines not on this page · raw message
Signature · 1 line
2.29.2
v2 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, rte_os.h contains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general.
First define required wrappers, then fix POSIX dependencies in Windows-enabled libraries and drivers, then eliminate POSIX symbols from Windows EAL API. Commits are arranged so that they all compile and are limited in scope; patches 5, 6, 7 can be squashed if needed.
No "Fixes" tags, because it's really an enhancement, preventing issues rather then solving direct ones.
v2: fix compilation issues in 3/7 and 6/7.
Dmitry Kozlyuk (7):
eal: add wrappers for POSIX string functions
eal: add macro for maximum path length
eal: add sleep API
eal: add asprintf() internal wrapper
lib: remove POSIX dependencies
drivers: remove POSIX dependencies
eal/windows: do not expose POSIX symbols
doc/guides/rel_notes/release_21_05.rst | 9 ++ drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +- drivers/common/mlx5/mlx5_common_pci.h | 1 + drivers/net/i40e/i40e_ethdev.c | 56 +++++------ lib/librte_cmdline/cmdline.c | 1 + lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 6 +- lib/librte_eal/common/eal_common_devargs.c | 7 +- lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_fbarray.c | 8 +- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_log.c | 5 +- lib/librte_eal/common/eal_common_options.c | 42 ++++---- lib/librte_eal/common/eal_common_timer.c | 5 +- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 4 +- .../common/eal_common_trace_utils.c | 13 +-- lib/librte_eal/common/eal_filesystem.h | 8 +- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_private.h | 23 +++++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 6 +- lib/librte_eal/include/rte_string_fns.h | 42 ++++++++ lib/librte_eal/include/rte_thread.h | 11 +++ lib/librte_eal/linux/include/rte_os.h | 6 +- lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 ++++++ lib/librte_eal/windows/eal_thread.c | 9 +- lib/librte_eal/windows/include/dirent.h | 21 ++-- lib/librte_eal/windows/include/rte_os.h | 99 ++----------------- lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++-- 39 files changed, 270 insertions(+), 207 deletions(-)
Signature · 1 line
2.29.2
PATCH v2 1/7 eal: add wrappers for POSIX string functions
POSIX strncasecmp(), strdup(), and strtok_r() have different names on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
Add wrappers as inline functions, because they're used from librte_kvargs, and thus cannot be in librte_eal; besides, implementation is trivial.
--- lib/librte_eal/common/eal_common_dev.c | 6 +-- lib/librte_eal/common/eal_common_devargs.c | 7 ++-- lib/librte_eal/common/eal_common_log.c | 5 ++- lib/librte_eal/common/eal_common_options.c | 12 +++--- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/include/rte_string_fns.h | 42 +++++++++++++++++++ 7 files changed, 60 insertions(+), 16 deletions(-)
lib/librte_eal/common/eal_common_dev.c +3 -3
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,if (!device_name) { event_cb->dev_name =NULL ; }else { - event_cb->dev_name =strdup (device_name); + event_cb->dev_name =rte_strdup (device_name);if (event_cb->dev_name ==NULL ) { ret = -ENOMEM ; goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str) end =strcspn (str,",/" );if (str[end] ==',' ) { - copy =strdup (&str[end +1 ]); + copy =rte_strdup (&str[end +1 ]); }else {/* '/' or '\0' */ - copy =strdup ("" ); + copy =rte_strdup ("" ); }if (copy ==NULL ) { rte_errno =ENOMEM ;
lib/librte_eal/common/eal_common_devargs.c +4 -3
@@ -18,6 +18,7 @@#include <rte_errno.h> #include <rte_kvargs.h> #include <rte_log.h> +#include <rte_string_fns.h> #include <rte_tailq.h> #include "eal_private.h"
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,* anything and keep referring only to it. */ if (devargs->data != devstr) { - devargs->data =strdup (devstr); + devargs->data =rte_strdup (devstr);if (devargs->data ==NULL ) {RTE_LOG (ERR ,EAL ,"OOM\n" ); ret = -ENOMEM ;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev) da->bus = bus;/* Parse eventual device arguments */ if (devname[i] ==',' ) - da->args =strdup (&devname[i +1 ]); + da->args =rte_strdup (&devname[i +1 ]);else - da->args =strdup ("" ); + da->args =rte_strdup ("" );if (da->args ==NULL ) {RTE_LOG (ERR ,EAL ,"not enough memory to parse arguments\n" );return -ENOMEM ;
lib/librte_eal/common/eal_common_log.c +3 -2
@@ -14,6 +14,7 @@#include <rte_eal.h> #include <rte_log.h> #include <rte_per_lcore.h> +#include <rte_string_fns.h> #include "eal_private.h"
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,if (regcomp (&opt_ll->re_match, regex,0 ) !=0 ) goto fail; }else if (pattern) { - opt_ll->pattern =strdup (pattern); + opt_ll->pattern =rte_strdup (pattern);if (opt_ll->pattern ==NULL ) goto fail; }else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)static int __rte_log_register (const char *name,int id) { -char *dup_name =strdup (name); +char *dup_name =rte_strdup (name);if (dup_name ==NULL )return -ENOMEM ;
lib/librte_eal/common/eal_common_options.c +6 -6
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (i =0 ; i < argc; i++) { - eal_args[i] =strdup (argv[i]); + eal_args[i] =rte_strdup (argv[i]);if (strcmp (argv[i],"--" ) ==0 )break ; }
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (j =0 ; i < argc; j++, i++) - eal_app_args[j] =strdup (argv[i]); + eal_app_args[j] =rte_strdup (argv[i]); eal_app_args[j] =NULL ;return 0 ;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)char *str, *level;int priority; - str =strdup (arg); + str =rte_strdup (arg);if (str ==NULL )return -1 ;
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)static enum rte_proc_type_t eal_parse_proc_type (const char *arg) { -if (strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 ) +if (rte_strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 )return RTE_PROC_PRIMARY ; -if (strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 ) +if (rte_strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 )return RTE_PROC_SECONDARY ; -if (strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 ) +if (rte_strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 )return RTE_PROC_AUTO ;return RTE_PROC_INVALID ;
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)if (strstr (field,"." ) ==NULL &&strstr (field,"->" ) ==NULL )return NULL ; - out =strdup (field); + out =rte_strdup (field);if (out ==NULL )return NULL ; p = out;
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)return -ENOMEM ; } - arg->val =strdup (val); + arg->val =rte_strdup (val);if (arg->val ==NULL ) {trace_err ("failed to allocate memory for %s" , val);free (arg);
lib/librte_eal/include/rte_string_fns.h +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 7 lines · Dmitry Kozlyuk
POSIX
strncasecmp(),strdup(), andstrtok_r()have different names on Windows, respectively,strnicmp(),_strdup(), andstrtok_s().Add wrappers as inline functions, because they're used from
librte_kvargs, and thus cannot be inlibrte_eal; besides, implementation is trivial.Signed-off-by Dmitry Kozlyuk <[email protected]>
Quoted 10 lines
--- lib/librte_eal/common/eal_common_dev.c | 6 +-- lib/librte_eal/common/eal_common_devargs.c | 7 ++-- lib/librte_eal/common/eal_common_log.c | 5 ++- lib/librte_eal/common/eal_common_options.c | 12 +++--- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/include/rte_string_fns.h | 42 +++++++++++++++++++ 7 files changed, 60 insertions(+), 16 deletions(-)
Rather than defining "rte_" versions of these functions, is it possible just to provide the unprefixed definitions of them for internal use? While this probably won't work for any functions used in public headers, for any functions only used in C files, we can use meson to detect the presence of the standard function and set a macro flag for the compatiblity version if not present. This is something we already support for the strlcpy/strlcat functions from libbsd, and it basically allows the well-known (and loved?) functions to be used directly, and saves DPDK developers having to worry about what "standard" functions can be used directly, and which can't.
/Bruce
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 11 lines
Rather than defining "
rte_" versions of these functions, is it possible just to provide the unprefixed definitions of them for internal use? While this probably won't work for any functions used in public headers, for any functions only used in C files, we can use meson to detect the presence of the standard function and set a macro flag for the compatiblity version if not present. This is something we already support for the strlcpy/strlcat functions from libbsd, and it basically allows the well-known (and loved?) functions to be used directly, and saves DPDK developers having to worry about what "standard" functions can be used directly, and which can't.
Hi Bruce,
You're asking a really good question here that highlights a fundamental issue:
Does the DPDK code base have an implied POSIX dependency, or should it only depend upon the standard C library and 'rte_ ' functions. This hasn't been an issue before, but Windows isn't 'POSIX' based.
Using "well-known" names for missing functions is ok where the definitions are in private header files, but if the headers are public, or the implementation is better done in a C file, then there can be a clash with the application which is likely dealing with the same issues.
There seem to be two viable approaches to handling this:
1. Expect the platform to provide POSIX semantic (through an external library
such as Cygwin). That way it becomes "an 'external' problem" and the DPDK
can use the "well-known" names and expected behaviour.
2. Provide the missing functionality, but wrap it in 'internal' header files
and 'rte_' versions to avoid link errors. This is the approach that Dmitry has
taken based on the guidance we've received.
For background, the approach I've taken with adding Windows support to SPDK is to create an 'external' library (https://wpdk.github.io) with header files that provide the missing POSIX functionality and functions with a prefix to avoid link errors. As a result, the whole of SPDK can now build and run unchanged.
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 38 lines · Nick Connolly
Rather than defining "
rte_" versions of these functions, is it possible just to provide the unprefixed definitions of them for internal use? While this probably won't work for any functions used in public headers, for any functions only used in C files, we can use meson to detect the presence of the standard function and set a macro flag for the compatiblity version if not present. This is something we already support for the strlcpy/strlcat functions from libbsd, and it basically allows the well-known (and loved?) functions to be used directly, and saves DPDK developers having to worry about what "standard" functions can be used directly, and which can't.Hi Bruce,
You're asking a really good question here that highlights a fundamental issue:
Does the DPDK code base have an implied POSIX dependency, or should it only
depend upon the standard C library and 'rte_' functions. This hasn't been an
issue before, but Windows isn't 'POSIX' based.
Using "well-known" names for missing functions is ok where the definitions
are in private header files, but if the headers are public, or the implementation
is better done in a C file, then there can be a clash with the application which
is likely dealing with the same issues.
There seem to be two viable approaches to handling this:
1. Expect the platform to provide POSIX semantic (through an external library
such as Cygwin). That way it becomes "an 'external' problem" and the DPDK
can use the "well-known" names and expected behaviour.
2. Provide the missing functionality, but wrap it in 'internal' header files
and 'rte_' versions to avoid link errors. This is the approach that Dmitry has
taken based on the guidance we've received.
Quoted 10 lines
For background, the approach I've taken with adding Windows support to SPDK
is to create an 'external' library ([1]https://wpdk.github.io) with header files that
provide the missing POSIX functionality and functions with a prefix to avoid link
errors. As a result, the whole of SPDK can now build and run unchanged. Regards,
Nick
Whatever about the specific implementation, I'd very much like to get to the point where we don't have to do search-replace for a bunch of functions like this, not to mention that we'd need to have checkpatch rules in place to ensure that further instances are not re-introduced.
As you say, though, the main issue will be whether we have instances in public header files or not. I would hope that no static inline functions in DPDK use any of the functions in question, but I'm not sure. Perhaps if there are instances in public headers those could be reworked to not use the problematic functions.
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an rte_strdup function for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to the c_args for DPDK building
* Inside our DPDK header (rte_string_fns.h in the strdup case), we can add a conditional define such as:
#ifdef RTE_NO_STRDUP
#define strdup(s) rte_strdup(s)
#endif
Thoughts on this?
/Bruce
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 12 lines
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an
rte_strdupfunction for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to thec_argsfor DPDK building
* Inside our DPDK header (rte_string_fns.hin the strdup case), we can add a conditional define such as:
Quoted 5 lines
#ifdef RTE_NO_STRDUP #define strdup(s) rte_strdup(s) #endifThoughts on this?
Looks like an elegant approach to me.
Nick
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
In reply to Bruce Richardson2021-02-22 14:26, Bruce Richardson:
Quoted 5 lines
As you say, though, the main issue will be whether we have instances in public header files or not. I would hope that no static inline functions in DPDK use any of the functions in question, but I'm not sure. Perhaps if there are instances in public headers those could be reworked to not use the problematic functions.
No instances of strdup(), strncasecmp(), or strtok_r() in any DPDK headers.
Quoted 11 lines
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an
rte_strdupfunction for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to thec_argsfor DPDK building
* Inside our DPDK header (rte_string_fns.hin the strdup case), we can add a conditional define such as:
Quoted 5 lines
#ifdef RTE_NO_STRDUP #define strdup(s) rte_strdup(s) #endifThoughts on this?
Looks good to me, I can rework the patchset like so.
Policy considerations:
1. The approach only applies to platform-agnostic functions, like str*(). Functions like sleep() still belong to librte_eal.
2. Deprecated functions, like index(3p), should be replaced with alternatives suggested by the standard.
3. If a standard C11 alternative is available, it should be used. This mostly applies to types, like u_int32 -> uint32_t (it's even in DPDK coding style already, isn't it?).
A nit: RTE_NO_XXX -> RTE_HAS_XXX (for consistency with existing macros)?
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 37 lines · Dmitry Kozlyuk
2021-02-22 14:26, Bruce Richardson:
Quoted 5 lines
As you say, though, the main issue will be whether we have instances in public header files or not. I would hope that no static inline functions in DPDK use any of the functions in question, but I'm not sure. Perhaps if there are instances in public headers those could be reworked to not use the problematic functions.
No instances of
strdup(),strncasecmp(), orstrtok_r()in any DPDK headers.Quoted 11 lines
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an
rte_strdupfunction for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to thec_argsfor DPDK building
* Inside our DPDK header (rte_string_fns.hin the strdup case), we can add a conditional define such as:Quoted 5 lines
#ifdef RTE_NO_STRDUP #define strdup(s) rte_strdup(s) #endifThoughts on this?
Looks good to me, I can rework the patchset like so.
Policy considerations:
1. The approach only applies to platform-agnostic functions, like str*(). Functions likesleep()still belong tolibrte_eal.
2. Deprecated functions, like index(3p), should be replaced with alternatives suggested by the standard.
3. If a standard C11 alternative is available, it should be used. This mostly applies to types, likeu_int32->uint32_t(it's even in DPDK coding style already, isn't it?).
Quoted 1 line
A nit:
RTE_NO_XXX->RTE_HAS_XXX(for consistency with existing macros)?
Sure, thanks.
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
2021-02-23 09:45, Bruce Richardson:
Quoted 38 lines · Dmitry Kozlyuk
Quoted 37 lines
2021-02-22 14:26, Bruce Richardson:
Quoted 5 lines
As you say, though, the main issue will be whether we have instances in public header files or not. I would hope that no static inline functions in DPDK use any of the functions in question, but I'm not sure. Perhaps if there are instances in public headers those could be reworked to not use the problematic functions.
No instances of
strdup(),strncasecmp(), orstrtok_r()in any DPDK headers.Quoted 11 lines
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an
rte_strdupfunction for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to thec_argsfor DPDK building
* Inside our DPDK header (rte_string_fns.hin the strdup case), we can add a conditional define such as:Quoted 5 lines
#ifdef RTE_NO_STRDUP #define strdup(s) rte_strdup(s) #endifThoughts on this?
Looks good to me, I can rework the patchset like so.
Policy considerations:
1. The approach only applies to platform-agnostic functions, like str*(). Functions likesleep()still belong tolibrte_eal.
2. Deprecated functions, like index(3p), should be replaced with alternatives suggested by the standard.
3. If a standard C11 alternative is available, it should be used. This mostly applies to types, likeu_int32->uint32_t(it's even in DPDK coding style already, isn't it?).
Quoted 3 lines
Quoted 1 line
A nit:
RTE_NO_XXX->RTE_HAS_XXX(for consistency with existing macros)?Sure, thanks.
There's a meson issue with cc.has_function():
https://github.com/mesonbuild/meson/issues/5628
What if we just define RTE_INTERNAL for librte_eal/windows/include/rte_os.h (and other public headers if need be) to distinguish the case when it's used from within DPDK?
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 7 lines
There's a meson issue with
cc.has_function():
https://github.com/mesonbuild/meson/issues/5628What if we just define
RTE_INTERNALforlibrte_eal/windows/include/rte_os.h(and other public headers if need be) to distinguish the case when it's used from within DPDK?
It's a pragmatic solution to the problem, but sadly it's not quite as clean as letting the build system determine if each 'wrapper' is needed. DPDK supports a variety of platforms and toolsets and my experience with SPDK suggests that we'll end up with compiler specific ifdef's. It's all protected by RTE_INTERNAL so it's not really a problem, but I wonder if it makes it easier for someone to accidentally introduce definitions outside of the #ifdef RTE_INTERNAL?
How about a new header rte_os_internal.h that contains the 'wrappers'? It gets included from rte_os.h only if RTE_INTERNAL is set and doesn't get installed so can't impact the user environment. I'm not sure I like it, but I guess we could do the same thing for every header that needs wrappers. I'm really 'thinking aloud' here and I'm not convinced it's the best route forward, so feel free to ignore. What I'm searching for is a way of wrapping that's clean and has a reasonably low risk of future human error.
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
2021-03-01 21:31, Nick Connolly:
Quoted 10 lines
Quoted 6 lines
There's a meson issue with
cc.has_function():
https://github.com/mesonbuild/meson/issues/5628What if we just define
RTE_INTERNALforlibrte_eal/windows/include/rte_os.h(and other public headers if need be) to distinguish the case when it's used from within DPDK?It's a pragmatic solution to the problem, but sadly it's not quite as clean as letting the build system determine if each 'wrapper' is needed. DPDK supports a variety of platforms and toolsets and my experience with SPDK suggests that we'll end up with compiler specific ifdef's.
I'd argue they are inevitable. Consider POSIX close(): if it's missing, what would be a correct fallback? It depends on the execution environment (OS). String function fallbacks, of course, are easily implemented from scratch.
Quoted 4 lines
It's all
protected byRTE_INTERNALso it's not really a problem, but I wonder if it makes it easier for someone to accidentally introduce definitions outside of the #ifdefRTE_INTERNAL?
Public functions without rte_ prefix shall not be introduced at all.
Remember the issue this patchset targets: export of POSIX symbols from EAL. They are already defined in a way DPDK consumes successfully. RTE_INTERNAL is a straightforward way to ensure symbols affect to other consumers. (I'm talking about macros; asprintf should be moved inside EAL in any case.)
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 7 lines
Quoted 4 lines
DPDK supports a variety of platforms and toolsets and my experience with SPDK suggests that we'll end up with compiler specific ifdef's.
I'd argue they are inevitable. Consider POSIX
close(): if it's missing, what would be a correct fallback? It depends on the execution environment (OS). String function fallbacks, of course, are easily implemented from scratch.
Agreed.
Quoted 1 line
Quoted 1 line
Public functions without
rte_prefix shall not be introduced at all.
Agreed. Perhaps as a separate patch we should consider validation rules to enforce the requirements.
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
In reply to Dmitry Kozlyuk27/02/2021 21:23, Dmitry Kozlyuk:
Quoted 39 lines
2021-02-23 09:45, Bruce Richardson:
Quoted 38 lines · Dmitry Kozlyuk
Quoted 37 lines
2021-02-22 14:26, Bruce Richardson:
Quoted 5 lines
As you say, though, the main issue will be whether we have instances in public header files or not. I would hope that no static inline functions in DPDK use any of the functions in question, but I'm not sure. Perhaps if there are instances in public headers those could be reworked to not use the problematic functions.
No instances of
strdup(),strncasecmp(), orstrtok_r()in any DPDK headers.Quoted 11 lines
For any functions, such as strdup, which are not in a public header I would suggest the following as a possible start point, based off what was done for strlcpy.
* In DPDK (probably EAL), define an
rte_strdupfunction for use as a fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the regular strdup function is available. If not, then add "-DRTE_NO_STRDUP" to thec_argsfor DPDK building
* Inside our DPDK header (rte_string_fns.hin the strdup case), we can add a conditional define such as:Quoted 5 lines
#ifdef RTE_NO_STRDUP #define strdup(s) rte_strdup(s) #endifThoughts on this?
Looks good to me, I can rework the patchset like so.
Policy considerations:
1. The approach only applies to platform-agnostic functions, like str*(). Functions likesleep()still belong tolibrte_eal.
2. Deprecated functions, like index(3p), should be replaced with alternatives suggested by the standard.
3. If a standard C11 alternative is available, it should be used. This mostly applies to types, likeu_int32->uint32_t(it's even in DPDK coding style already, isn't it?).
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
A nit:
RTE_NO_XXX->RTE_HAS_XXX(for consistency with existing macros)?Sure, thanks.
There's a meson issue with
cc.has_function():
https://github.com/mesonbuild/meson/issues/5628
The meson issue can be fixed or workarounded probably. Is it the reason for the RTE_INTERNAL proposal below?
Quoted 3 lines
What if we just define
RTE_INTERNALforlibrte_eal/windows/include/rte_os.h(and other public headers if need be) to distinguish the case when it's used from within DPDK?
I'm not sure to follow the need for RTE_INTERNAL.
In general, 3 guidelines:
- avoid inline functions in public headers
- mark exported internal functions with __rte_internal and in version.map
- export internal functions in a separate file
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
In reply to Nick ConnollyQuoted 8 lines · Nick Connolly
There seem to be two viable approaches to handling this:
1. Expect the platform to provide POSIX semantic (through an external library
such as Cygwin). That way it becomes "an 'external' problem" and the DPDK
can use the "well-known" names and expected behaviour.
I'd prefer not to see this be a requirement of the platform. There have been multiple attempts over the years to provide a POSIX surfaces on Windows which arguably haven't been that successful.
It would be helpful if DPDK dependence on POSIX APIs were limited to be only as necessary to improve portability to non-POSIX platforms.
Ty
Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
Quoted 8 lines
Quoted 5 lines
There seem to be two viable approaches to handling this:
1. Expect the platform to provide POSIX semantic (through an external
...I'd prefer not to see this be a requirement of the platform. There have been multiple attempts over the years to provide a POSIX surfaces on Windows which arguably haven't been that successful.
+1
'viable' was the wrong word - I can't see a general-purpose POSIX surface giving a good outcome.
Quoted 2 lines
It would be helpful if DPDK dependence on POSIX APIs were limited to be only as necessary to improve portability to non-POSIX platforms.
PATCH v2 2/7 eal: add macro for maximum path length
In reply to Dmitry KozlyukPath length limit is PATH_MAX on Unix and _MAX_PATH on Windows. Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX in "common" multiprocess code, because it's really Unix-specific.
--- lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 8 +++---- lib/librte_eal/common/eal_common_options.c | 20 +++++++++--------- .../common/eal_common_trace_utils.c | 9 ++++---- lib/librte_eal/common/eal_filesystem.h | 8 +++---- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 2 ++ lib/librte_eal/linux/include/rte_os.h | 2 ++ lib/librte_eal/windows/include/dirent.h | 21 +++++++------------ lib/librte_eal/windows/include/rte_os.h | 2 ++ 12 files changed, 41 insertions(+), 39 deletions(-)
lib/librte_eal/common/eal_common_config.c +1 -1
@@ -18,7 +18,7 @@ static struct rte_config rte_config = { };/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX ]; +static char runtime_dir[RTE_PATH_MAX ];/* internal configuration */ static struct internal_config internal_config;
lib/librte_eal/common/eal_common_fbarray.c +4 -4
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)static int resize_and_map (int fd,void *addr,size_t len) { -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *map_addr;if (eal_file_truncate (fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz) {size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];struct used_mask *msk;struct mem_area *ma =NULL ;void *data =NULL ;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr) {struct mem_area *ma =NULL , *tmp =NULL ;size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *data =NULL ;int fd =-1 ;
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)struct mem_area *tmp =NULL ;size_t mmap_len;int fd, ret; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];const struct internal_config *internal_conf =eal_get_internal_configuration ();
lib/librte_eal/common/eal_common_options.c +10 -10
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);struct shared_driver {TAILQ_ENTRY (shared_driver) next; -char name[PATH_MAX ]; +char name[RTE_PATH_MAX ];void * lib_handle; };
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)return -1 ; }memset (solib,0 ,sizeof (*solib)); -strlcpy (solib->name, path,PATH_MAX ); +strlcpy (solib->name, path,RTE_PATH_MAX );TAILQ_INSERT_TAIL (&solib_list, solib, next);return 0 ;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path) {DIR *d =NULL ;struct dirent *dent =NULL ; -char sopath[PATH_MAX ]; +char sopath[RTE_PATH_MAX ];if (path ==NULL || *path =='\0' )return 0 ;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)/* if not root, check down one level first */ if (strcmp (dirpath,"/" ) !=0 ) { -static __threadchar last_dir_checked[PATH_MAX ]; -char copy[PATH_MAX ]; +static __threadchar last_dir_checked[RTE_PATH_MAX ]; +char copy[RTE_PATH_MAX ];const char *dir; -strlcpy (copy, dirpath,PATH_MAX ); +strlcpy (copy, dirpath,RTE_PATH_MAX ); dir =dirname (copy); -if (strncmp (dir, last_dir_checked,PATH_MAX ) !=0 ) { +if (strncmp (dir, last_dir_checked,RTE_PATH_MAX ) !=0 ) {if (verify_perms (dir) !=0 )return -1 ; -strlcpy (last_dir_checked, dir,PATH_MAX ); +strlcpy (last_dir_checked, dir,RTE_PATH_MAX ); } }
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname) pathname, strerror(errno)); goto out; } -if (strnlen (realp,PATH_MAX ) ==PATH_MAX ) { -RTE_LOG (ERR ,EAL ,"Error, driver path greater than PATH_MAX\n" ); +if (strnlen (realp,RTE_PATH_MAX ) ==RTE_PATH_MAX ) { +RTE_LOG (ERR ,EAL ,"Error, driver path greater than RTE_PATH_MAX\n" ); goto out; }
lib/librte_eal/common/eal_common_trace_utils.c +5 -4
@@ -369,11 +369,11 @@ trace_mkdir(void)static int trace_meta_save (struct trace *trace) { -char file_name[PATH_MAX ]; +char file_name[RTE_PATH_MAX ];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/metadata" , trace->dir); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/metadata" , trace->dir);if (rc <0 )return rc;
@@ -400,11 +400,12 @@ static int trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr, uint32_t cnt) { - char file_name[PATH_MAX]; + char file_name[RTE_PATH_MAX];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/channel0_%d" , trace->dir, cnt); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/channel0_%d" , + trace->dir, cnt);if (rc <0 )return rc;
lib/librte_eal/common/eal_filesystem.h +4 -4
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);static inline const char *eal_runtime_config_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),RUNTIME_CONFIG_FNAME );
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)static inline const char *eal_mp_socket_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),MP_SOCKET_FNAME );
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {static inline const char *eal_hugepage_info_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_INFO_FNAME );
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)static inline const char *eal_hugepage_data_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_DATA_FNAME );
lib/librte_eal/common/eal_hugepages.h +1 -1
@@ -9,7 +9,7 @@#include <stdint.h> #include <limits.h> -#define MAX_HUGEPAGE_PATH PATH_MAX +#define MAX_HUGEPAGE_PATH RTE_PATH_MAX/** * Structure used to store information about hugepages that we mapped
lib/librte_eal/common/eal_internal_cfg.h +1 -1
@@ -27,7 +27,7 @@*/ struct hugepage_info {uint64_t hugepage_sz;/**< size of a huge page */ -char hugedir[PATH_MAX ];/**< dir where hugetlbfs is mounted */ +char hugedir[RTE_PATH_MAX ];/**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES ];/**< number of hugepages of that size on each socket */ int lock_descriptor;/**< file descriptor for hugepage dir */
lib/librte_eal/common/eal_trace.h +1 -1
@@ -51,7 +51,7 @@ struct trace_arg { };struct trace { -char dir[PATH_MAX ]; +char dir[RTE_PATH_MAX ];int dir_offset;int register_errno;bool status;
lib/librte_eal/freebsd/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <pthread_np.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpuset_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) do \ { \
lib/librte_eal/linux/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <sched.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpu_set_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) CPU_AND(dst, src1, src2)#define RTE_CPU_OR (dst, src1, src2) CPU_OR(dst, src1, src2)
lib/librte_eal/windows/include/dirent.h +8 -13
@@ -28,11 +28,6 @@#include <sys/stat.h> #include <errno.h> -/* Maximum length of file name */ -#if !defined(PATH_MAX ) -# define PATH_MAX MAX_PATH -#endif -/* File type flags for d_type */ #define DT_UNKNOWN 0#define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {int d_type;/* File name */ -wchar_t d_name[PATH_MAX ]; +wchar_t d_name[RTE_PATH_MAX ]; };typedef struct _wdirent _wdirent ;
@@ -113,7 +108,7 @@ struct dirent {int d_type;/* File name */ -char d_name[PATH_MAX ]; +char d_name[RTE_PATH_MAX ]; };typedef struct dirent dirent ;
@@ -388,12 +383,12 @@ opendir(const char *dirname)/* Allocate memory for DIR structure */ dirp = (DIR *)malloc (sizeof (struct DIR ));if (dirp) { -wchar_t wname[PATH_MAX ]; +wchar_t wname[RTE_PATH_MAX ];size_t n;/* Convert directory name to wide-character string */ - error =dirent_mbstowcs_s (&n, wname,PATH_MAX , - dirname,PATH_MAX ); + error =dirent_mbstowcs_s (&n, wname,RTE_PATH_MAX , + dirname,RTE_PATH_MAX );if (!error) {/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)/* Attempt to convert file name to multi-byte string */ error =dirent_wcstombs_s (&n, dirp->ent.d_name, -PATH_MAX , datap->cFileName,PATH_MAX ); +RTE_PATH_MAX , datap->cFileName,RTE_PATH_MAX );/* * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)*/ if (error && datap->cAlternateFileName[0 ] !='\0' ) { error =dirent_wcstombs_s ( - &n, dirp->ent.d_name,PATH_MAX , - datap->cAlternateFileName,PATH_MAX ); + &n, dirp->ent.d_name,RTE_PATH_MAX , + datap->cAlternateFileName,RTE_PATH_MAX ); }if (!error) {
lib/librte_eal/windows/include/rte_os.h +2 -0
@@ -20,6 +20,8 @@extern "C" {#endif +#define RTE_PATH_MAX _MAX_PATH +/* limits.h replacement, value as in <windows.h> */ #ifndef PATH_MAX #define PATH_MAX _MAX_PATH
Signature · 1 line
2.29.2
PATCH v2 3/7 eal: add sleep API
In reply to Dmitry KozlyukPOSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +3 -0
@@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL {
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 3/7] eal: add sleep API
Quoted 18 lines
Subject: [dpdk-dev] [PATCH v2 3/7] eal: add sleep API
External email: Use caution opening links or attachments
POSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
[snip]
lib/librte_eal/version.map EXPERIMENTAL { · line 416
Quoted 10 lines
lib/librte_eal/version.map index renamed from lib/librte_eal/version.map +0
-0fce90a112..106864469 100644
lib/librte_eal/version.map +2
-0@@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05
Spaces, should be tab.
Quoted 34 lines
lib/librte_eal/version.map +1
-0+ rte_thread_sleep; }; INTERNAL {lib/librte_eal/windows/eal_thread.c +8
-2@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /* @@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +} --2.29.2
PATCH v2 4/7 eal: add asprintf() internal wrapper
In reply to Dmitry KozlyukPOSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().
--- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 8 ++--- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++ 7 files changed, 56 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +1 -1
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback =calloc (1 ,sizeof (*callback));if (callback ==NULL )return NULL ; -if (asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) { +if (eal_asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) {free (callback);return NULL ; }
lib/librte_eal/common/eal_common_options.c +4 -4
@@ -1435,7 +1435,7 @@ available_cores(void)return NULL ;/* first sequence */ -if (asprintf (&str,"%d" , idx) <0 ) +if (eal_asprintf (&str,"%d" , idx) <0 )return NULL ; previous = idx; sequence =0 ;
@@ -1452,7 +1452,7 @@ available_cores(void)/* finish current sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
@@ -1461,7 +1461,7 @@ available_cores(void) }/* new sequence */ -if (asprintf (&tmp,"%s,%d" , str, idx) <0 ) { +if (eal_asprintf (&tmp,"%s,%d" , str, idx) <0 ) {free (str);return NULL ; }
@@ -1473,7 +1473,7 @@ available_cores(void)/* finish last sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
lib/librte_eal/common/eal_common_trace.c +1 -1
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) fixup =trace_metadata_fixup_field (in);if (fixup !=NULL ) in = fixup; - rc =asprintf (&field,"%s %s %s;\n" , + rc =eal_asprintf (&field,"%s %s %s;\n" ,RTE_PER_LCORE (ctf_field) !=NULL ?RTE_PER_LCORE (ctf_field) :"" , datatype, in);
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)for (i =0 ; i <RTE_DIM (ctf_reserved_words); i++) {if (strcmp (field, ctf_reserved_words[i]) !=0 )continue ; -if (asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) +if (eal_asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) out =NULL ;return out; }
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)return -ENAMETOOLONG ; } -if (asprintf (&dir_path,"%s/" , val) ==-1 ) { +if (eal_asprintf (&dir_path,"%s/" , val) ==-1 ) {trace_err ("failed to copy directory: %s" ,strerror (errno));return -ENOMEM ; }
lib/librte_eal/common/eal_private.h +18 -0
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* Allocate a buffer large enough to hold the formatted string +* and perform formatting, equivalent to Unix asprintf(3). +* +* @param buffer +* Receives a pointer to allocated memory, call free(buffer) to deallocate. +* @param format +* Format string. +* @return +* Number of bytes allocated on success, (-1) on failure. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); +#else +#define eal_asprintf asprintf +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.2
PATCH v2 5/7 lib: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().
Locally rename Windows _close() to standard close().
--- lib/librte_cmdline/cmdline.c | 1 + lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++++++++++------- 4 files changed, 13 insertions(+), 9 deletions(-)
lib/librte_cmdline/cmdline.c +1 -0
@@ -19,6 +19,7 @@#include "cmdline_private.h" #ifdef RTE_EXEC_ENV_WINDOWS +#define close _close#define write _write#endif
lib/librte_ethdev/rte_class_eth.c +1 -1
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,return -1 ;/* not a representor port */ /* Parse devargs representor values. */ - values =strdup (value); + values =rte_strdup (value);if (values ==NULL )return -1 ;memset (&representors,0 ,sizeof (representors));
lib/librte_ethdev/rte_ethdev.c +1 -1
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)struct rte_kvargs_pair *pair;char *letter; - arglist->str =strdup (str_in); + arglist->str =rte_strdup (str_in);if (arglist->str ==NULL )return -ENOMEM ;
lib/librte_kvargs/rte_kvargs.c +10 -7
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)/* Copy the const char *params to a modifiable string * to pass to rte_strsplit */ - kvlist->str =strdup (params); + kvlist->str =rte_strdup (params);if (kvlist->str ==NULL )return -1 ;/* browse each key/value pair and add it in kvlist */ str = kvlist->str; -while ((str =strtok_r (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { +while ((str =rte_strtok (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { i = kvlist->count;if (i >=RTE_KVARGS_MAX )return -1 ; - kvlist->pairs[i].key =strtok_r (str,RTE_KVARGS_KV_DELIM , &ctx2); - kvlist->pairs[i].value =strtok_r (NULL ,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].key =rte_strtok ( + str,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].value =rte_strtok ( +NULL ,RTE_KVARGS_KV_DELIM , &ctx2);if (kvlist->pairs[i].key ==NULL || kvlist->pairs[i].value ==NULL )return -1 ;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)if (str[0 ] =='[' ) {/* Find the end of the list. */ while (str[strlen (str) -1 ] !=']' ) { -/* Restore the comma erased by strtok_r(). */ +/* Restore the comma erased by rte_strtok(). */ if (ctx1 ==NULL || ctx1[0 ] =='\0' )return -1 ;/* no closing bracket */ str[strlen (str)] =',' ;/* Parse until next comma. */ - str =strtok_r (NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1); + str =rte_strtok ( +NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1);if (str ==NULL )return -1 ;/* no closing bracket */ }
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],if (valid_ends ==NULL )return rte_kvargs_parse (args, valid_keys); - copy =strdup (args); + copy =rte_strdup (args);if (copy ==NULL )return NULL ;
Signature · 1 line
2.29.2
PATCH v2 6/7 drivers: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strncasecmp() with EAL rte_strncasecmp(). Replace POSIX strtok_r() with EAL rte_strtok(). Replace POSIX strdup() with EAL rte_strdup().
---
i40e: checkpatches.sh complains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.
drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +- drivers/common/mlx5/mlx5_common_pci.h | 1 + drivers/net/i40e/i40e_ethdev.c | 56 +++++++++++++-------------- 6 files changed, 36 insertions(+), 34 deletions(-)
drivers/bus/pci/private.h +1 -1
@@ -92,7 +92,7 @@ struct mapped_pci_resource {TAILQ_ENTRY (mapped_pci_resource) next;struct rte_pci_addr pci_addr; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];int nb_maps;struct pci_map maps[PCI_MAX_RESOURCE ];struct pci_msix_table msix_table;
drivers/bus/vdev/vdev.c +2 -2
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args) devargs->bus = &rte_vdev_bus;if (args) - devargs->args =strdup (args); + devargs->args =rte_strdup (args);else - devargs->args =strdup ("" ); + devargs->args =rte_strdup ("" ); ret =strlcpy (devargs->name, name,sizeof (devargs->name));if (ret <0 || ret >= (int )sizeof (devargs->name)) {
drivers/bus/vdev/vdev_params.c +2 -1
@@ -8,6 +8,7 @@#include <rte_bus.h> #include <rte_kvargs.h> #include <rte_errno.h> +#include <rte_string_fns.h> #include "vdev_logs.h" #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,char *name;/* cannot pass const dev->name to rte_kvargs_process() */ - name =strdup (dev->name); + name =rte_strdup (dev->name);if (name ==NULL )return -1 ; ret = rte_kvargs_process(kvlist,
drivers/common/mlx5/mlx5_common_pci.c +2 -2
@@ -88,7 +88,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,return *ret; } nstr_org = nstr; - found =strtok_r (nstr,":" , &refstr); + found =rte_strtok (nstr,":" , &refstr);if (!found) goto err; do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key, goto err; } *ret |= class_val; - found =strtok_r (NULL ,":" , &refstr); + found =rte_strtok (NULL ,":" , &refstr); }while (found); err:free (nstr_org);
drivers/common/mlx5/mlx5_common_pci.h +1 -0
@@ -45,6 +45,7 @@ extern "C" {#include <rte_pci.h> #include <rte_bus_pci.h> +#include <rte_string_fns.h> #include <mlx5_common.h>
drivers/net/i40e/i40e_ethdev.c +28 -28
138 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
Quoted 16 lines
Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
External email: Use caution opening links or attachments
Replace POSIX
strncasecmp()with EALrte_strncasecmp(). Replace POSIXstrtok_r()with EALrte_strtok(). Replace POSIXstrdup()with EALrte_strdup().Signed-off-by Dmitry Kozlyuk <[email protected]>---
i40e:checkpatches.shcomplains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.
Quoted 4 lines
drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +-
bus_cmdline_options_handler in mlx5_common_pci.c has a call to strdup which needs to be renamed to rte_strdup (Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )
Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
Quoted 16 lines · Tal Shnaiderman
Quoted 16 lines
Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
External email: Use caution opening links or attachments
Replace POSIX
strncasecmp()with EALrte_strncasecmp(). Replace POSIXstrtok_r()with EALrte_strtok(). Replace POSIXstrdup()with EALrte_strdup().Signed-off-by Dmitry Kozlyuk <[email protected]>---
i40e:checkpatches.shcomplains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.
Quoted 8 lines
Quoted 4 lines
drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +-
bus_cmdline_options_handlerinmlx5_common_pci.chas a call to strdup which needs to be renamed torte_strdup(Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )
Frankly speaking I don't understand why such changes are useful/needed. Patch description does not explain/prove it.
Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
Quoted 22 lines · Andrew Rybchenko
Quoted 21 lines · Tal Shnaiderman
Quoted 20 lines
Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
External email: Use caution opening links or attachments
Replace POSIX
strncasecmp()with EALrte_strncasecmp(). Replace POSIXstrtok_r()with EALrte_strtok(). Replace POSIXstrdup()with EALrte_strdup().Signed-off-by Dmitry Kozlyuk <[email protected]>---
i40e:checkpatches.shcomplains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 4 +-
Quoted 7 lines
Quoted 3 lines
bus_cmdline_options_handlerinmlx5_common_pci.chas a call to strdup which needs to be renamed torte_strdup(Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )Frankly speaking I don't understand why such changes are useful/needed. Patch description does not explain/prove it.
Please see the cover letter (better to partially repeat in each patch?):
https://mails.dpdk.org/archives/dev/2021-February/199981.html
Driver code using POSIX functions is not really portable without a shim. Having a shim in public API is wrong, it makes DPDK expose non-DPDK symbols.
An alternative approach would be to make the shim DPDK-internal. It would require just a change in #includes for drivers and libs. My doubt is whether EAL should emulate POSIX.
PATCH v2 7/7 eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukExposing POSIX symbols could break consumer POSIX compatibility code.
* Make renaming of close() and unlink() private to EAL.
* Remove renaming of strncasecmp(), strtok_r(), and sleep() in favor of using EAL wrappers. Similarly remove PATH_MAX macro.
* Replace index(3p), which is not available on Windows, with strchr(3), as recommended by POSIX.1-2008. strerror_r() is only used inside EAL, rename it only where it's needed. Same for asprintf(), it has an internal EAL wrapper and is removed from public API.
--- doc/guides/rel_notes/release_21_05.rst | 9 ++ lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/common/eal_private.h | 5 ++ lib/librte_eal/freebsd/include/rte_os.h | 4 +- lib/librte_eal/linux/include/rte_os.h | 4 +- lib/librte_eal/windows/include/rte_os.h | 99 ++-------------------- 7 files changed, 29 insertions(+), 98 deletions(-)
doc/guides/rel_notes/release_21_05.rst +9 -0
@@ -84,6 +84,15 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols + has been incorrect and could conflict with consumer POSIX implementations. + Wrappers are provided for + ``strtok_r(3p)`` (``rte_strtok``), + ``strncasecmp(3p)`` (``rte_strncasecmp``), + ``sleep(3p)`` (``rte_thread_sleep``), + ``PATH_MAX`` (``RTE_PATH_MAX``). + Removed are ``strerror_r(3p)`` and ``asprintf(3p)``. + ABI Changes -----------
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#ifdef RTE_EXEC_ENV_WINDOWS +#define strerror_r (a, b, c) strerror_s(b, c, a) +#endif +RTE_DEFINE_PER_LCORE (int, _rte_errno); const char *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_private.h +5 -0
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);#define eal_asprintf asprintf#endif +#ifdef RTE_EXEC_ENV_WINDOWS +#define close _close +#define unlink _unlink +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/freebsd/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* freebsd OS. Functions will be added in future releases. +* freebsd OS. It must not define symbols without "rte_" prefix. */ #include <pthread_np.h>
lib/librte_eal/linux/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* linux OS. Functions will be added in future releases. +* linux OS. It must not define symbols without "rte_" prefix. */ #include <sched.h>
lib/librte_eal/windows/include/rte_os.h +6 -93
122 lines not on this page · raw message
Signature · 1 line
2.29.2
Quoted 20 lines
Subject: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
External email: Use caution opening links or attachments
Exposing POSIX symbols could break consumer POSIX compatibility code.
* Make renaming of
close()andunlink()private to EAL.* Remove renaming of
strncasecmp(),strtok_r(), andsleep()in favor of using EAL wrappers. Similarly removePATH_MAXmacro.* Replace index(3p), which is not available on Windows, with strchr(3), as recommended by POSIX.1-2008.
strerror_r()is only used inside EAL, rename it only where it's needed. Same forasprintf(), it has an internal EAL wrapper and is removed from public API.Signed-off-by Dmitry Kozlyuk <[email protected]>---
[snip]
Quoted 49 lines
lib/librte_eal/windows/include/rte_os.h +2
-26@@ -6,15 +6,11 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition -* which are not supported natively or named differently in the -* Windows OS. It must not include Windows-specific headers. +* This header should contain any function/macro definition +* which are not supported natively or named differently in Windows OS. */ -#include <stdarg.h> -#include <stdio.h> #include <stdlib.h> -#include <string.h> #ifdef __cplusplusextern "C" {@@ -22,101 +18,18 @@ extern "C" {#define RTE_PATH_MAX _MAX_PATH -/* limits.h replacement, value as in <windows.h> */ -#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
lib/librte_eal/windows/include/rte_os.h extern "C" { · line 56
Quoted 10 lines
lib/librte_eal/windows/include/rte_os.h +0
-10-#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
mlx5 uses close() in mlx5.c and is broken after this change above, BTW why not add an rte_close instead of local definition?
Quoted 5 lines
lib/librte_eal/windows/include/rte_os.h +0
-5- -#ifndef unlink -#define unlink _unlink -#endif -
[snip]
On Sun, 21 Feb 2021 08:59:50 +0000, Tal Shnaiderman wrote:
[...]
Quoted 5 lines
lib/librte_eal/windows/include/rte_os.h extern "C" { · line 61
Quoted 3 lines
lib/librte_eal/windows/include/rte_os.h +0
-3-#ifndef close -#define close _close -#endif mlx5 uses
close()inmlx5.cand is broken after this change above, BTW why not add anrte_closeinstead of local definition?
I'm reluctant to add file manipulation API to EAL. It would be replication of POSIX with "rte_" prefix, while standard C has everything needed to deal with files (and IOCTLs are platform-specific code anyway). I think libraries and PMDs striving to be cross-platform should move to using FILE* some day. For now, local definitions keep them running without any risk of breakage.
Thanks for all your comments, it's weird I didn't hit the failures locally. Will fix in v3.
Quoted 15 lines
Subject: Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
External email: Use caution opening links or attachments
On Sun, 21 Feb 2021 08:59:50 +0000, Tal Shnaiderman wrote:
[...]Quoted 5 lines
lib/librte_eal/windows/include/rte_os.h extern "C" { · line 61
Quoted 3 lines
lib/librte_eal/windows/include/rte_os.h +0
-3-#ifndef close -#define close _close -#endif mlx5 uses
close()inmlx5.cand is broken after this change above, BTW whynot add an
rte_closeinstead of local definition?
Quoted 8 lines
I'm reluctant to add file manipulation API to EAL. It would be replication of POSIX with "
rte_" prefix, while standard C has everything needed to deal with files (and IOCTLs are platform-specific code anyway). I think libraries and PMDs striving to be cross-platform should move to using FILE* some day. For now, local definitions keep them running without any risk of breakage.Thanks for all your comments, it's weird I didn't hit the failures locally. Will fix in v3.
You might be missing the DevX SDK installation, without it meson will skip the mlx5 build.
You can get it either by installation WIOF2 2.60 [1] or get only the SDK from [2] (I attached it to the Bugzilla ticket when asked the UNH team to add mlx5 compilation to CI.
[1] - https://www.mellanox.com/products/adapter-software/ethernet/windows/winof-2
[2] - https://bugs.dpdk.org/show_bug.cgi?id=620
On Sun, 21 Feb 2021 11:58:39 +0000, Tal Shnaiderman wrote:
[...]
Quoted 9 lines
Quoted 2 lines
Thanks for all your comments, it's weird I didn't hit the failures locally. Will fix in v3.
You might be missing the DevX SDK installation, without it meson will skip the mlx5 build.
You can get it either by installation WIOF2 2.60 [1] or get only the SDK from [2] (I attached it to the Bugzilla ticket when asked the UNH team to add mlx5 compilation to CI.
[1] - https://www.mellanox.com/products/adapter-software/ethernet/windows/winof-2
[2] - https://bugs.dpdk.org/show_bug.cgi?id=620
Indeed it was the case, thank you again.
v3 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, rte_os.h contains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general.
First define required wrappers, then fix POSIX dependencies in Windows-enabled libraries and drivers, then eliminate POSIX symbols from Windows EAL API. Commits are arranged so that they all compile and are limited in scope; patches 5, 6, 7 can be squashed if needed.
No "Fixes" tags, because it's really an enhancement, preventing issues rather then solving direct ones.
v3:
* Fix indentation in 3/7 (Tal Shnaiderman).
* Fix build failures in 6/7 and 7/7 (Tal Shnaiderman).
v2:
* Fix compilation issues in 3/7 and 6/7 (self).
Dmitry Kozlyuk (7):
eal: add wrappers for POSIX string functions
eal: add macro for maximum path length
eal: add sleep API
eal: add asprintf() internal wrapper
lib: remove POSIX dependencies
drivers: remove POSIX dependencies
eal/windows: do not expose POSIX symbols
doc/guides/rel_notes/release_21_05.rst | 9 ++ drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 6 +- drivers/common/mlx5/mlx5_common_pci.h | 1 + drivers/net/i40e/i40e_ethdev.c | 56 +++++------ drivers/net/mlx5/mlx5.c | 4 + lib/librte_cmdline/cmdline.c | 1 + lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 6 +- lib/librte_eal/common/eal_common_devargs.c | 7 +- lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_fbarray.c | 8 +- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_log.c | 5 +- lib/librte_eal/common/eal_common_options.c | 42 ++++---- lib/librte_eal/common/eal_common_timer.c | 5 +- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 4 +- .../common/eal_common_trace_utils.c | 13 +-- lib/librte_eal/common/eal_filesystem.h | 8 +- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_private.h | 23 +++++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 6 +- lib/librte_eal/include/rte_string_fns.h | 42 ++++++++ lib/librte_eal/include/rte_thread.h | 11 +++ lib/librte_eal/linux/include/rte_os.h | 6 +- lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 ++++++ lib/librte_eal/windows/eal_thread.c | 9 +- lib/librte_eal/windows/include/dirent.h | 21 ++-- lib/librte_eal/windows/include/rte_os.h | 99 ++----------------- lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++-- 40 files changed, 275 insertions(+), 208 deletions(-)
Signature · 1 line
2.29.2
PATCH v3 1/7 eal: add wrappers for POSIX string functions
POSIX strncasecmp(), strdup(), and strtok_r() have different names on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
Add wrappers as inline functions, because they're used from librte_kvargs, and thus cannot be in librte_eal; besides, implementation is trivial.
--- lib/librte_eal/common/eal_common_dev.c | 6 +-- lib/librte_eal/common/eal_common_devargs.c | 7 ++-- lib/librte_eal/common/eal_common_log.c | 5 ++- lib/librte_eal/common/eal_common_options.c | 12 +++--- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/include/rte_string_fns.h | 42 +++++++++++++++++++ 7 files changed, 60 insertions(+), 16 deletions(-)
lib/librte_eal/common/eal_common_dev.c +3 -3
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,if (!device_name) { event_cb->dev_name =NULL ; }else { - event_cb->dev_name =strdup (device_name); + event_cb->dev_name =rte_strdup (device_name);if (event_cb->dev_name ==NULL ) { ret = -ENOMEM ; goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str) end =strcspn (str,",/" );if (str[end] ==',' ) { - copy =strdup (&str[end +1 ]); + copy =rte_strdup (&str[end +1 ]); }else {/* '/' or '\0' */ - copy =strdup ("" ); + copy =rte_strdup ("" ); }if (copy ==NULL ) { rte_errno =ENOMEM ;
lib/librte_eal/common/eal_common_devargs.c +4 -3
@@ -18,6 +18,7 @@#include <rte_errno.h> #include <rte_kvargs.h> #include <rte_log.h> +#include <rte_string_fns.h> #include <rte_tailq.h> #include "eal_private.h"
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,* anything and keep referring only to it. */ if (devargs->data != devstr) { - devargs->data =strdup (devstr); + devargs->data =rte_strdup (devstr);if (devargs->data ==NULL ) {RTE_LOG (ERR ,EAL ,"OOM\n" ); ret = -ENOMEM ;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev) da->bus = bus;/* Parse eventual device arguments */ if (devname[i] ==',' ) - da->args =strdup (&devname[i +1 ]); + da->args =rte_strdup (&devname[i +1 ]);else - da->args =strdup ("" ); + da->args =rte_strdup ("" );if (da->args ==NULL ) {RTE_LOG (ERR ,EAL ,"not enough memory to parse arguments\n" );return -ENOMEM ;
lib/librte_eal/common/eal_common_log.c +3 -2
@@ -14,6 +14,7 @@#include <rte_eal.h> #include <rte_log.h> #include <rte_per_lcore.h> +#include <rte_string_fns.h> #include "eal_private.h"
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,if (regcomp (&opt_ll->re_match, regex,0 ) !=0 ) goto fail; }else if (pattern) { - opt_ll->pattern =strdup (pattern); + opt_ll->pattern =rte_strdup (pattern);if (opt_ll->pattern ==NULL ) goto fail; }else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)static int __rte_log_register (const char *name,int id) { -char *dup_name =strdup (name); +char *dup_name =rte_strdup (name);if (dup_name ==NULL )return -ENOMEM ;
lib/librte_eal/common/eal_common_options.c +6 -6
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (i =0 ; i < argc; i++) { - eal_args[i] =strdup (argv[i]); + eal_args[i] =rte_strdup (argv[i]);if (strcmp (argv[i],"--" ) ==0 )break ; }
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)return -1 ;for (j =0 ; i < argc; j++, i++) - eal_app_args[j] =strdup (argv[i]); + eal_app_args[j] =rte_strdup (argv[i]); eal_app_args[j] =NULL ;return 0 ;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)char *str, *level;int priority; - str =strdup (arg); + str =rte_strdup (arg);if (str ==NULL )return -1 ;
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)static enum rte_proc_type_t eal_parse_proc_type (const char *arg) { -if (strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 ) +if (rte_strncasecmp (arg,"primary" ,sizeof ("primary" )) ==0 )return RTE_PROC_PRIMARY ; -if (strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 ) +if (rte_strncasecmp (arg,"secondary" ,sizeof ("secondary" )) ==0 )return RTE_PROC_SECONDARY ; -if (strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 ) +if (rte_strncasecmp (arg,"auto" ,sizeof ("auto" )) ==0 )return RTE_PROC_AUTO ;return RTE_PROC_INVALID ;
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)if (strstr (field,"." ) ==NULL &&strstr (field,"->" ) ==NULL )return NULL ; - out =strdup (field); + out =rte_strdup (field);if (out ==NULL )return NULL ; p = out;
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)return -ENOMEM ; } - arg->val =strdup (val); + arg->val =rte_strdup (val);if (arg->val ==NULL ) {trace_err ("failed to allocate memory for %s" , val);free (arg);
lib/librte_eal/include/rte_string_fns.h +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
Quoted 7 lines · Dmitry Kozlyuk
POSIX
strncasecmp(),strdup(), andstrtok_r()have different names on Windows, respectively,strnicmp(),_strdup(), andstrtok_s().Add wrappers as inline functions, because they're used from
librte_kvargs, and thus cannot be inlibrte_eal; besides, implementation is trivial.Signed-off-by Dmitry Kozlyuk <[email protected]>
[snip]
lib/librte_eal/include/rte_string_fns.h rte_strlcat(char *dst, const char *src, size_t size) · line 159
Quoted 13 lines
lib/librte_eal/include/rte_string_fns.h +13
-0+/** +* @internal +* strdup(3) replacement for systems that don't have it. +*/ +static inline char * +rte_strdup (const char *str) +{ +#ifdef RTE_EXEC_ENV_WINDOWS +return _strdup (str); +#else +return strdup (str); +#endif +}
Allocating memory using rte_strdup() I'd use rte_free() to release it. I guess it will fail badly.
So, I think that a different, more specific prefix is required for POSIX wrappers.
Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
Quoted 5 lines
Allocating memory using
rte_strdup()I'd userte_free()to release it. I guess it will fail badly.
So, I think that a different, more specific prefix is required for POSIX wrappers.
Andrew: my understanding of Bruce's proposal is that the strdup() name will now be kept (in this case through an inline definition), so I think this will be ok. However, your comment reminded me of something else that it's probably worth mentioning as an aside:
As a general guideline on Windows, memory allocated within a shared library is best freed within the same DLL to ensure it goes back to the correct heap. So we'd want to avoid calling strdup and then returning the value to the application for it to free (hopefully this doesn't happen). With an inline definition there's no change in behaviour, but adding rte_strdup (or anything else that calls malloc) into librte_eal might be an issue.
Regards,
Nick
Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
Quoted 9 lines · Nick Connolly
Quoted 5 lines
Allocating memory using
rte_strdup()I'd userte_free()to release it. I guess it will fail badly.
So, I think that a different, more specific prefix is required for POSIX wrappers.Andrew: my understanding of Bruce's proposal is that the
strdup()name will now be kept (in this case through an inline definition), so I think this will be ok.
Very good, glad to hear it. Thanks.
Quoted 13 lines
However, your comment reminded me of something else that it's probably worth mentioning as an aside:
As a general guideline on Windows, memory allocated within a shared library is best freed within the same DLL to ensure it goes back to the correct heap. So we'd want to avoid calling strdup and then returning the value to the application for it to free (hopefully this doesn't happen). With an inline definition there's no change in behaviour, but adding
rte_strdup(or anything else that calls malloc) intolibrte_ealmight be an issue.Regards,
Nick
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
In reply to Dmitry KozlyukQuoted 9 lines
POSIX
strncasecmp(),strdup(), andstrtok_r()have different names on Windows, respectively,strnicmp(),_strdup(), andstrtok_s().Add wrappers as inline functions, because they're used from
librte_kvargs, and thus cannot be inlibrte_eal; besides, implementation is trivial.Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 2/7 eal: add macro for maximum path length
In reply to Dmitry KozlyukPath length limit is PATH_MAX on Unix and _MAX_PATH on Windows. Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX in "common" multiprocess code, because it's really Unix-specific.
--- lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 8 +++---- lib/librte_eal/common/eal_common_options.c | 20 +++++++++--------- .../common/eal_common_trace_utils.c | 9 ++++---- lib/librte_eal/common/eal_filesystem.h | 8 +++---- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 2 ++ lib/librte_eal/linux/include/rte_os.h | 2 ++ lib/librte_eal/windows/include/dirent.h | 21 +++++++------------ lib/librte_eal/windows/include/rte_os.h | 2 ++ 12 files changed, 41 insertions(+), 39 deletions(-)
lib/librte_eal/common/eal_common_config.c +1 -1
@@ -18,7 +18,7 @@ static struct rte_config rte_config = { };/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX ]; +static char runtime_dir[RTE_PATH_MAX ];/* internal configuration */ static struct internal_config internal_config;
lib/librte_eal/common/eal_common_fbarray.c +4 -4
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)static int resize_and_map (int fd,void *addr,size_t len) { -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *map_addr;if (eal_file_truncate (fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz) {size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];struct used_mask *msk;struct mem_area *ma =NULL ;void *data =NULL ;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr) {struct mem_area *ma =NULL , *tmp =NULL ;size_t page_sz, mmap_len; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];void *data =NULL ;int fd =-1 ;
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)struct mem_area *tmp =NULL ;size_t mmap_len;int fd, ret; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];const struct internal_config *internal_conf =eal_get_internal_configuration ();
lib/librte_eal/common/eal_common_options.c +10 -10
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);struct shared_driver {TAILQ_ENTRY (shared_driver) next; -char name[PATH_MAX ]; +char name[RTE_PATH_MAX ];void * lib_handle; };
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)return -1 ; }memset (solib,0 ,sizeof (*solib)); -strlcpy (solib->name, path,PATH_MAX ); +strlcpy (solib->name, path,RTE_PATH_MAX );TAILQ_INSERT_TAIL (&solib_list, solib, next);return 0 ;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path) {DIR *d =NULL ;struct dirent *dent =NULL ; -char sopath[PATH_MAX ]; +char sopath[RTE_PATH_MAX ];if (path ==NULL || *path =='\0' )return 0 ;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)/* if not root, check down one level first */ if (strcmp (dirpath,"/" ) !=0 ) { -static __threadchar last_dir_checked[PATH_MAX ]; -char copy[PATH_MAX ]; +static __threadchar last_dir_checked[RTE_PATH_MAX ]; +char copy[RTE_PATH_MAX ];const char *dir; -strlcpy (copy, dirpath,PATH_MAX ); +strlcpy (copy, dirpath,RTE_PATH_MAX ); dir =dirname (copy); -if (strncmp (dir, last_dir_checked,PATH_MAX ) !=0 ) { +if (strncmp (dir, last_dir_checked,RTE_PATH_MAX ) !=0 ) {if (verify_perms (dir) !=0 )return -1 ; -strlcpy (last_dir_checked, dir,PATH_MAX ); +strlcpy (last_dir_checked, dir,RTE_PATH_MAX ); } }
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname) pathname, strerror(errno)); goto out; } -if (strnlen (realp,PATH_MAX ) ==PATH_MAX ) { -RTE_LOG (ERR ,EAL ,"Error, driver path greater than PATH_MAX\n" ); +if (strnlen (realp,RTE_PATH_MAX ) ==RTE_PATH_MAX ) { +RTE_LOG (ERR ,EAL ,"Error, driver path greater than RTE_PATH_MAX\n" ); goto out; }
lib/librte_eal/common/eal_common_trace_utils.c +5 -4
@@ -369,11 +369,11 @@ trace_mkdir(void)static int trace_meta_save (struct trace *trace) { -char file_name[PATH_MAX ]; +char file_name[RTE_PATH_MAX ];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/metadata" , trace->dir); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/metadata" , trace->dir);if (rc <0 )return rc;
@@ -400,11 +400,12 @@ static int trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr, uint32_t cnt) { - char file_name[PATH_MAX]; + char file_name[RTE_PATH_MAX];FILE *f;int rc; - rc =snprintf (file_name,PATH_MAX ,"%s/channel0_%d" , trace->dir, cnt); + rc =snprintf (file_name,RTE_PATH_MAX ,"%s/channel0_%d" , + trace->dir, cnt);if (rc <0 )return rc;
lib/librte_eal/common/eal_filesystem.h +4 -4
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);static inline const char *eal_runtime_config_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),RUNTIME_CONFIG_FNAME );
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)static inline const char *eal_mp_socket_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),MP_SOCKET_FNAME );
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {static inline const char *eal_hugepage_info_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_INFO_FNAME );
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)static inline const char *eal_hugepage_data_path (void ) { -static char buffer[PATH_MAX ];/* static so auto-zeroed */ +static char buffer[RTE_PATH_MAX ];/* static so auto-zeroed */ snprintf (buffer,sizeof (buffer),"%s/%s" ,rte_eal_get_runtime_dir (),HUGEPAGE_DATA_FNAME );
lib/librte_eal/common/eal_hugepages.h +1 -1
@@ -9,7 +9,7 @@#include <stdint.h> #include <limits.h> -#define MAX_HUGEPAGE_PATH PATH_MAX +#define MAX_HUGEPAGE_PATH RTE_PATH_MAX/** * Structure used to store information about hugepages that we mapped
lib/librte_eal/common/eal_internal_cfg.h +1 -1
@@ -27,7 +27,7 @@*/ struct hugepage_info {uint64_t hugepage_sz;/**< size of a huge page */ -char hugedir[PATH_MAX ];/**< dir where hugetlbfs is mounted */ +char hugedir[RTE_PATH_MAX ];/**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES ];/**< number of hugepages of that size on each socket */ int lock_descriptor;/**< file descriptor for hugepage dir */
lib/librte_eal/common/eal_trace.h +1 -1
@@ -51,7 +51,7 @@ struct trace_arg { };struct trace { -char dir[PATH_MAX ]; +char dir[RTE_PATH_MAX ];int dir_offset;int register_errno;bool status;
lib/librte_eal/freebsd/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <pthread_np.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpuset_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) do \ { \
lib/librte_eal/linux/include/rte_os.h +2 -0
@@ -13,6 +13,8 @@#include <sched.h> +#define RTE_PATH_MAX PATH_MAX +typedef cpu_set_t rte_cpuset_t ;#define RTE_CPU_AND (dst, src1, src2) CPU_AND(dst, src1, src2)#define RTE_CPU_OR (dst, src1, src2) CPU_OR(dst, src1, src2)
lib/librte_eal/windows/include/dirent.h +8 -13
@@ -28,11 +28,6 @@#include <sys/stat.h> #include <errno.h> -/* Maximum length of file name */ -#if !defined(PATH_MAX ) -# define PATH_MAX MAX_PATH -#endif -/* File type flags for d_type */ #define DT_UNKNOWN 0#define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {int d_type;/* File name */ -wchar_t d_name[PATH_MAX ]; +wchar_t d_name[RTE_PATH_MAX ]; };typedef struct _wdirent _wdirent ;
@@ -113,7 +108,7 @@ struct dirent {int d_type;/* File name */ -char d_name[PATH_MAX ]; +char d_name[RTE_PATH_MAX ]; };typedef struct dirent dirent ;
@@ -388,12 +383,12 @@ opendir(const char *dirname)/* Allocate memory for DIR structure */ dirp = (DIR *)malloc (sizeof (struct DIR ));if (dirp) { -wchar_t wname[PATH_MAX ]; +wchar_t wname[RTE_PATH_MAX ];size_t n;/* Convert directory name to wide-character string */ - error =dirent_mbstowcs_s (&n, wname,PATH_MAX , - dirname,PATH_MAX ); + error =dirent_mbstowcs_s (&n, wname,RTE_PATH_MAX , + dirname,RTE_PATH_MAX );if (!error) {/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)/* Attempt to convert file name to multi-byte string */ error =dirent_wcstombs_s (&n, dirp->ent.d_name, -PATH_MAX , datap->cFileName,PATH_MAX ); +RTE_PATH_MAX , datap->cFileName,RTE_PATH_MAX );/* * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)*/ if (error && datap->cAlternateFileName[0 ] !='\0' ) { error =dirent_wcstombs_s ( - &n, dirp->ent.d_name,PATH_MAX , - datap->cAlternateFileName,PATH_MAX ); + &n, dirp->ent.d_name,RTE_PATH_MAX , + datap->cAlternateFileName,RTE_PATH_MAX ); }if (!error) {
lib/librte_eal/windows/include/rte_os.h +2 -0
@@ -20,6 +20,8 @@extern "C" {#endif +#define RTE_PATH_MAX _MAX_PATH +/* limits.h replacement, value as in <windows.h> */ #ifndef PATH_MAX #define PATH_MAX _MAX_PATH
Signature · 1 line
2.29.2
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 2/7] eal: add macro for maximum path length
Quoted 8 lines
Path length limit is
PATH_MAXon Unix and_MAX_PATHon Windows. AddRTE_PATH_MAXmacro for use in OS-independent code. KeepPATH_MAX
in "common" multiprocess code, because it's really Unix-specific.Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 3/7 eal: add sleep API
In reply to Dmitry KozlyukPOSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +3 -0
@@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL {
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v3 3/7] eal: add sleep API
Hi Dmitry,
lib/librte_eal/windows/eal_thread.c rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) · line 163
Quoted 5 lines
lib/librte_eal/windows/eal_thread.c +5
-0+void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
There's probably no benefit in returning the 'void' value - I'd suggest just call Sleep().
Regards,
Nick
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 3/7] eal: add sleep API
In reply to Dmitry KozlyukQuoted 6 lines
POSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 4/7 eal: add asprintf() internal wrapper
In reply to Dmitry KozlyukPOSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().
--- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 8 ++--- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++ 7 files changed, 56 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +1 -1
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback =calloc (1 ,sizeof (*callback));if (callback ==NULL )return NULL ; -if (asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) { +if (eal_asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) {free (callback);return NULL ; }
lib/librte_eal/common/eal_common_options.c +4 -4
@@ -1435,7 +1435,7 @@ available_cores(void)return NULL ;/* first sequence */ -if (asprintf (&str,"%d" , idx) <0 ) +if (eal_asprintf (&str,"%d" , idx) <0 )return NULL ; previous = idx; sequence =0 ;
@@ -1452,7 +1452,7 @@ available_cores(void)/* finish current sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
@@ -1461,7 +1461,7 @@ available_cores(void) }/* new sequence */ -if (asprintf (&tmp,"%s,%d" , str, idx) <0 ) { +if (eal_asprintf (&tmp,"%s,%d" , str, idx) <0 ) {free (str);return NULL ; }
@@ -1473,7 +1473,7 @@ available_cores(void)/* finish last sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
lib/librte_eal/common/eal_common_trace.c +1 -1
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) fixup =trace_metadata_fixup_field (in);if (fixup !=NULL ) in = fixup; - rc =asprintf (&field,"%s %s %s;\n" , + rc =eal_asprintf (&field,"%s %s %s;\n" ,RTE_PER_LCORE (ctf_field) !=NULL ?RTE_PER_LCORE (ctf_field) :"" , datatype, in);
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)for (i =0 ; i <RTE_DIM (ctf_reserved_words); i++) {if (strcmp (field, ctf_reserved_words[i]) !=0 )continue ; -if (asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) +if (eal_asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) out =NULL ;return out; }
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)return -ENAMETOOLONG ; } -if (asprintf (&dir_path,"%s/" , val) ==-1 ) { +if (eal_asprintf (&dir_path,"%s/" , val) ==-1 ) {trace_err ("failed to copy directory: %s" ,strerror (errno));return -ENOMEM ; }
lib/librte_eal/common/eal_private.h +18 -0
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* Allocate a buffer large enough to hold the formatted string +* and perform formatting, equivalent to Unix asprintf(3). +* +* @param buffer +* Receives a pointer to allocated memory, call free(buffer) to deallocate. +* @param format +* Format string. +* @return +* Number of bytes allocated on success, (-1) on failure. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); +#else +#define eal_asprintf asprintf +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.2
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 4/7] eal: add asprintf() internal wrapper
Quoted 6 lines
POSIX
asprintf()is unavailable on Windows.
Addeal_asprintf()wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro forasprintf().Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 5/7 lib: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().
Locally rename Windows _close() to standard close().
--- lib/librte_cmdline/cmdline.c | 1 + lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_kvargs/rte_kvargs.c | 17 ++++++++++------- 4 files changed, 13 insertions(+), 9 deletions(-)
lib/librte_cmdline/cmdline.c +1 -0
@@ -19,6 +19,7 @@#include "cmdline_private.h" #ifdef RTE_EXEC_ENV_WINDOWS +#define close _close#define write _write#endif
lib/librte_ethdev/rte_class_eth.c +1 -1
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,return -1 ;/* not a representor port */ /* Parse devargs representor values. */ - values =strdup (value); + values =rte_strdup (value);if (values ==NULL )return -1 ;memset (&representors,0 ,sizeof (representors));
lib/librte_ethdev/rte_ethdev.c +1 -1
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)struct rte_kvargs_pair *pair;char *letter; - arglist->str =strdup (str_in); + arglist->str =rte_strdup (str_in);if (arglist->str ==NULL )return -ENOMEM ;
lib/librte_kvargs/rte_kvargs.c +10 -7
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)/* Copy the const char *params to a modifiable string * to pass to rte_strsplit */ - kvlist->str =strdup (params); + kvlist->str =rte_strdup (params);if (kvlist->str ==NULL )return -1 ;/* browse each key/value pair and add it in kvlist */ str = kvlist->str; -while ((str =strtok_r (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { +while ((str =rte_strtok (str,RTE_KVARGS_PAIRS_DELIM , &ctx1)) !=NULL ) { i = kvlist->count;if (i >=RTE_KVARGS_MAX )return -1 ; - kvlist->pairs[i].key =strtok_r (str,RTE_KVARGS_KV_DELIM , &ctx2); - kvlist->pairs[i].value =strtok_r (NULL ,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].key =rte_strtok ( + str,RTE_KVARGS_KV_DELIM , &ctx2); + kvlist->pairs[i].value =rte_strtok ( +NULL ,RTE_KVARGS_KV_DELIM , &ctx2);if (kvlist->pairs[i].key ==NULL || kvlist->pairs[i].value ==NULL )return -1 ;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)if (str[0 ] =='[' ) {/* Find the end of the list. */ while (str[strlen (str) -1 ] !=']' ) { -/* Restore the comma erased by strtok_r(). */ +/* Restore the comma erased by rte_strtok(). */ if (ctx1 ==NULL || ctx1[0 ] =='\0' )return -1 ;/* no closing bracket */ str[strlen (str)] =',' ;/* Parse until next comma. */ - str =strtok_r (NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1); + str =rte_strtok ( +NULL ,RTE_KVARGS_PAIRS_DELIM , &ctx1);if (str ==NULL )return -1 ;/* no closing bracket */ }
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],if (valid_ends ==NULL )return rte_kvargs_parse (args, valid_keys); - copy =strdup (args); + copy =rte_strdup (args);if (copy ==NULL )return NULL ;
Signature · 1 line
2.29.2
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 5/7] lib: remove POSIX dependencies
Quoted 6 lines
Replace POSIX
strtok_r()with EALrte_strtok().
Replace POSIXstrdup()with EALrte_strdup().
Locally rename Windows_close()to standardclose().Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 6/7 drivers: remove POSIX dependencies
In reply to Dmitry KozlyukReplace POSIX strncasecmp() with EAL rte_strncasecmp(). Replace POSIX strtok_r() with EAL rte_strtok(). Replace POSIX strdup() with EAL rte_strdup().
---
i40e: checkpatches.sh complains about long lines (it's ~85).
I doubt that mechanical fix would keep the code readable. It's on 5th level of indentation, so I'd extract a function, but would like to hear from maintainers first.
drivers/bus/pci/private.h | 2 +- drivers/bus/vdev/vdev.c | 4 +- drivers/bus/vdev/vdev_params.c | 3 +- drivers/common/mlx5/mlx5_common_pci.c | 6 +-- drivers/common/mlx5/mlx5_common_pci.h | 1 + drivers/net/i40e/i40e_ethdev.c | 56 +++++++++++++-------------- drivers/net/mlx5/mlx5.c | 4 ++ 7 files changed, 41 insertions(+), 35 deletions(-)
drivers/bus/pci/private.h +1 -1
@@ -92,7 +92,7 @@ struct mapped_pci_resource {TAILQ_ENTRY (mapped_pci_resource) next;struct rte_pci_addr pci_addr; -char path[PATH_MAX ]; +char path[RTE_PATH_MAX ];int nb_maps;struct pci_map maps[PCI_MAX_RESOURCE ];struct pci_msix_table msix_table;
drivers/bus/vdev/vdev.c +2 -2
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args) devargs->bus = &rte_vdev_bus;if (args) - devargs->args =strdup (args); + devargs->args =rte_strdup (args);else - devargs->args =strdup ("" ); + devargs->args =rte_strdup ("" ); ret =strlcpy (devargs->name, name,sizeof (devargs->name));if (ret <0 || ret >= (int )sizeof (devargs->name)) {
drivers/bus/vdev/vdev_params.c +2 -1
@@ -8,6 +8,7 @@#include <rte_bus.h> #include <rte_kvargs.h> #include <rte_errno.h> +#include <rte_string_fns.h> #include "vdev_logs.h" #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,char *name;/* cannot pass const dev->name to rte_kvargs_process() */ - name =strdup (dev->name); + name =rte_strdup (dev->name);if (name ==NULL )return -1 ; ret = rte_kvargs_process(kvlist,
drivers/common/mlx5/mlx5_common_pci.c +3 -3
@@ -82,13 +82,13 @@ bus_cmdline_options_handler(__rte_unused const char *key,char *refstr =NULL ; *ret =0 ; - nstr =strdup (class_names); + nstr =rte_strdup (class_names);if (!nstr) { *ret = -ENOMEM ;return *ret; } nstr_org = nstr; - found =strtok_r (nstr,":" , &refstr); + found =rte_strtok (nstr,":" , &refstr);if (!found) goto err; do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key, goto err; } *ret |= class_val; - found =strtok_r (NULL ,":" , &refstr); + found =rte_strtok (NULL ,":" , &refstr); }while (found); err:free (nstr_org);
drivers/common/mlx5/mlx5_common_pci.h +1 -0
@@ -45,6 +45,7 @@ extern "C" {#include <rte_pci.h> #include <rte_bus_pci.h> +#include <rte_string_fns.h> #include <mlx5_common.h>
drivers/net/i40e/i40e_ethdev.c +28 -28
138 lines not on this page · raw message
drivers/net/mlx5/mlx5.c +4 -0
@@ -41,6 +41,10 @@#include "mlx5_flow_os.h" #include "rte_pmd_mlx5.h" +#ifdef RTE_EXEC_ENV_WINDOWS +#define close _close +#endif +/* Device parameter to enable RX completion queue compression. */ #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
Signature · 1 line
2.29.2
Re: [dpdk-dev] [EXTERNAL] [PATCH v3 6/7] drivers: remove POSIX dependencies
Quoted 6 lines
Replace POSIX
strncasecmp()with EALrte_strncasecmp(). Replace POSIXstrtok_r()with EALrte_strtok(). Replace POSIXstrdup()with EALrte_strdup().Signed-off-by Dmitry Kozlyuk <[email protected]>---
PATCH v3 7/7 eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukExposing POSIX symbols could break consumer POSIX compatibility code.
* Make renaming of close() and unlink() private to EAL.
* Remove renaming of strncasecmp(), strtok_r(), and sleep() in favor of using EAL wrappers. Similarly remove PATH_MAX macro.
* Replace index(3p), which is not available on Windows, with strchr(3), as recommended by POSIX.1-2008. strerror_r() is only used inside EAL, rename it only where it's needed. Same for asprintf(), it has an internal EAL wrapper and is removed from public API.
--- doc/guides/rel_notes/release_21_05.rst | 9 ++ lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/common/eal_private.h | 5 ++ lib/librte_eal/freebsd/include/rte_os.h | 4 +- lib/librte_eal/linux/include/rte_os.h | 4 +- lib/librte_eal/windows/include/rte_os.h | 99 ++-------------------- 7 files changed, 29 insertions(+), 98 deletions(-)
doc/guides/rel_notes/release_21_05.rst +9 -0
@@ -84,6 +84,15 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols + has been incorrect and could conflict with consumer POSIX implementations. + Wrappers are provided for + ``strtok_r(3p)`` (``rte_strtok``), + ``strncasecmp(3p)`` (``rte_strncasecmp``), + ``sleep(3p)`` (``rte_thread_sleep``), + ``PATH_MAX`` (``RTE_PATH_MAX``). + Removed are ``strerror_r(3p)`` and ``asprintf(3p)``. + ABI Changes -----------
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#ifdef RTE_EXEC_ENV_WINDOWS +#define strerror_r (a, b, c) strerror_s(b, c, a) +#endif +RTE_DEFINE_PER_LCORE (int, _rte_errno); const char *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_private.h +5 -0
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);#define eal_asprintf asprintf#endif +#ifdef RTE_EXEC_ENV_WINDOWS +#define close _close +#define unlink _unlink +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/freebsd/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* freebsd OS. Functions will be added in future releases. +* freebsd OS. It must not define symbols without "rte_" prefix. */ #include <pthread_np.h>
lib/librte_eal/linux/include/rte_os.h +2 -2
@@ -6,9 +6,9 @@#define _RTE_OS_H_/** -* This is header should contain any function/macro definition +* This header should contain any function/macro definition * which are not supported natively or named differently in the -* linux OS. Functions will be added in future releases. +* linux OS. It must not define symbols without "rte_" prefix. */ #include <sched.h>
lib/librte_eal/windows/include/rte_os.h +6 -93
122 lines not on this page · raw message
Signature · 1 line
2.29.2
Quoted 7 lines
Exposing POSIX symbols could break consumer POSIX compatibility code.
* Make renaming of
close()andunlink()private to EAL.* Remove renaming of
strncasecmp(),strtok_r(), andsleep()in favor of using EAL wrappers. Similarly removePATH_MAXmacro.
Quoted 7 lines
* Replace index(3p), which is not available on Windows, with strchr(3), as recommended by POSIX.1-2008.
strerror_r()is only used inside EAL, rename it only where it's needed. Same forasprintf(), it has an internal EAL wrapper and is removed from public API.Signed-off-by Dmitry Kozlyuk <[email protected]>---
Quoted 10 lines
On Windows,
rte_os.hcontains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general.First define required wrappers, then fix POSIX dependencies in Windows-enabled libraries and drivers, then eliminate POSIX symbols from Windows EAL API. Commits are arranged so that they all compile and are limited in scope; patches 5, 6, 7 can be squashed if needed.
Quoted 9 lines
No "Fixes" tags, because it's really an enhancement, preventing issues rather then solving direct ones.
v3:
* Fix indentation in 3/7 (Tal Shnaiderman).
* Fix build failures in 6/7 and 7/7 (Tal Shnaiderman).
v2:
* Fix compilation issues in 3/7 and 6/7 (self).
v4 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, rte_os.h contains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v4:
* Instead of creating wrappers and replacing POSIX names in lib/ and drivers/, provide POSIX names only to internal consumers.
* Move renaming from librte_cmdline to librte_eal.
Dmitry Kozlyuk (4):
eal: add sleep API
eal: add asprintf() internal wrapper
build: indicate usage at build time for public headers eal/windows: do not expose POSIX symbols
config/meson.build | 3 + doc/guides/rel_notes/release_21_05.rst | 3 + lib/librte_cmdline/cmdline.c | 4 - lib/librte_cmdline/cmdline_socket.c | 4 - lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 10 +- lib/librte_eal/common/eal_common_timer.c | 5 +- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/include/rte_thread.h | 11 ++ lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 +++++ lib/librte_eal/windows/eal_thread.c | 9 +- lib/librte_eal/windows/include/rte_os.h | 103 ++++-------------- 19 files changed, 122 insertions(+), 105 deletions(-)
Signature · 1 line
2.29.2
PATCH v4 1/4 eal: add sleep API
POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +3 -0
@@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL {
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.2
PATCH v4 2/4 eal: add asprintf() internal wrapper
In reply to Dmitry KozlyukPOSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().
--- lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 8 ++--- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++ 7 files changed, 56 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +1 -1
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback =calloc (1 ,sizeof (*callback));if (callback ==NULL )return NULL ; -if (asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) { +if (eal_asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) {free (callback);return NULL ; }
lib/librte_eal/common/eal_common_options.c +4 -4
@@ -1435,7 +1435,7 @@ available_cores(void)return NULL ;/* first sequence */ -if (asprintf (&str,"%d" , idx) <0 ) +if (eal_asprintf (&str,"%d" , idx) <0 )return NULL ; previous = idx; sequence =0 ;
@@ -1452,7 +1452,7 @@ available_cores(void)/* finish current sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
@@ -1461,7 +1461,7 @@ available_cores(void) }/* new sequence */ -if (asprintf (&tmp,"%s,%d" , str, idx) <0 ) { +if (eal_asprintf (&tmp,"%s,%d" , str, idx) <0 ) {free (str);return NULL ; }
@@ -1473,7 +1473,7 @@ available_cores(void)/* finish last sequence */ if (sequence) { -if (asprintf (&tmp,"%s-%d" , str, previous) <0 ) { +if (eal_asprintf (&tmp,"%s-%d" , str, previous) <0 ) {free (str);return NULL ; }
lib/librte_eal/common/eal_common_trace.c +1 -1
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) fixup =trace_metadata_fixup_field (in);if (fixup !=NULL ) in = fixup; - rc =asprintf (&field,"%s %s %s;\n" , + rc =eal_asprintf (&field,"%s %s %s;\n" ,RTE_PER_LCORE (ctf_field) !=NULL ?RTE_PER_LCORE (ctf_field) :"" , datatype, in);
lib/librte_eal/common/eal_common_trace_ctf.c +1 -1
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)for (i =0 ; i <RTE_DIM (ctf_reserved_words); i++) {if (strcmp (field, ctf_reserved_words[i]) !=0 )continue ; -if (asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) +if (eal_asprintf (&out,"_%s" , ctf_reserved_words[i]) ==-1 ) out =NULL ;return out; }
lib/librte_eal/common/eal_common_trace_utils.c +1 -1
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)return -ENAMETOOLONG ; } -if (asprintf (&dir_path,"%s/" , val) ==-1 ) { +if (eal_asprintf (&dir_path,"%s/" , val) ==-1 ) {trace_err ("failed to copy directory: %s" ,strerror (errno));return -ENOMEM ; }
lib/librte_eal/common/eal_private.h +18 -0
@@ -745,4 +745,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* Allocate a buffer large enough to hold the formatted string +* and perform formatting, equivalent to Unix asprintf(3). +* +* @param buffer +* Receives a pointer to allocated memory, call free(buffer) to deallocate. +* @param format +* Format string. +* @return +* Number of bytes allocated on success, (-1) on failure. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); +#else +#define eal_asprintf asprintf +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper
Quoted 2 lines · Dmitry Kozlyuk
POSIX
asprintf()is unavailable on Windows.
AFAIK asprintf() is not a POSIX API, it is a GNU extension that has also been implemented in some BSDs.
Quoted 6 lines
Add
eal_asprintf()wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro forasprintf().Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>---
PATCH v4 3/4 build: indicate usage at build time for public headers
In reply to Dmitry KozlyukDPDK code often relies on functions that are not standard C, but are found on all platforms, even if by slightly different names. Some headers provide macros or inline difinitions for such symbols. However, when placed in public headers, these symbols are unnecessarily exposed to DPDK consumers.
Define RTE_BUILD_INTERNAL at build time.
In its presense public headers can provide additional definitions for internal code, but hide them from external consumers.
--- config/meson.build | 3 +++ 1 file changed, 3 insertions(+)
config/meson.build +3 -0
@@ -287,6 +287,9 @@ dpdk_conf.set('RTE_EAL_VFIO', is_linux) # specify -D_GNU_SOURCE unconditionally add_project_arguments('-D_GNU_SOURCE', language: 'c') +# specify that sources are building as part of DPDK +add_project_arguments('-DRTE_BUILD_INTERNAL', language: 'c') + # specify -D__BSD_VISIBLE for FreeBSD if is_freebsd add_project_arguments('-D__BSD_VISIBLE', language: 'c')
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers
06/03/2021 01:04, Dmitry Kozlyuk:
Quoted 9 lines
DPDK code often relies on functions that are not standard C, but are found on all platforms, even if by slightly different names. Some headers provide macros or inline difinitions for such symbols. However, when placed in public headers, these symbols are unnecessarily exposed to DPDK consumers.
Define
RTE_BUILD_INTERNALat build time.
In its presense public headers can provide additional definitions for internal code, but hide them from external consumers.
Is there a way to split public and internal headers, and avoid playing with RTE_BUILD_INTERNAL?
PATCH v4 4/4 eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukExposing POSIX symbols could break consumer POSIX compatibility code. Export POSIX names for commonly used symbols only to internal consumers. Move definitions used only by EAL inside EAL.
Replace deprecated [r]index() with standard str[r]chr().
--- doc/guides/rel_notes/release_21_05.rst | 3 + lib/librte_cmdline/cmdline.c | 4 - lib/librte_cmdline/cmdline_socket.c | 4 - lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/windows/include/rte_os.h | 103 ++++----------------- 6 files changed, 27 insertions(+), 93 deletions(-)
doc/guides/rel_notes/release_21_05.rst +3 -0
@@ -84,6 +84,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal/windows: Removed POSIX symbol export from ``<rte_os.h>``. + It has been incorrect and could conflict with consumer POSIX implementations. + ABI Changes -----------
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/windows/include/rte_os.h +19 -84
126 lines not on this page · raw message
Signature · 1 line
2.29.2
Quoted 29 lines · Dmitry Kozlyuk
On Windows,
rte_os.hcontains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.v4:
* Instead of creating wrappers and replacing POSIX names inlib/anddrivers/, provide POSIX names only to internal consumers.
* Move renaming fromlibrte_cmdlinetolibrte_eal.Dmitry Kozlyuk (4):
eal: add sleep API
eal: addasprintf()internal wrapper
build: indicate usage at build time for public headers eal/windows: do not expose POSIX symbolsconfig/meson.build | 3 + doc/guides/rel_notes/release_21_05.rst | 3 + lib/librte_cmdline/cmdline.c | 4 - lib/librte_cmdline/cmdline_socket.c | 4 - lib/librte_eal/common/eal_common_errno.c | 4 + lib/librte_eal/common/eal_common_lcore.c | 2 +- lib/librte_eal/common/eal_common_options.c | 10 +- lib/librte_eal/common/eal_common_timer.c | 5 +- lib/librte_eal/common/eal_common_trace.c | 2 +- lib/librte_eal/common/eal_common_trace_ctf.c | 2 +- .../common/eal_common_trace_utils.c | 2 +- lib/librte_eal/common/eal_private.h | 18 +++
Quoted 9 lines
lib/librte_eal/include/rte_thread.h | 11 ++ lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 +++++ lib/librte_eal/windows/eal_thread.c | 9 +- lib/librte_eal/windows/include/rte_os.h | 103 ++++-------------- 19 files changed, 122 insertions(+), 105 deletions(-)
Sorry, ack-ed the v1 of this patch series by mistake. This is the real ACK!
v5 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v5:
* Unify series with removing Windows networking shim to eliminate dependency between series and CI failures.
* RTE_BUILD_INTERNAL -> rte_os_internal.h (Thomas Monjalon).
* Remove release notes: hidden symbols were never part of API.
v4:
* Instead of creating wrappers and replacing POSIX names in lib/ and drivers/, provide POSIX names only to internal consumers.
* Move renaming from librte_cmdline to librte_eal.
Dmitry Kozlyuk (5):
eal: add sleep API
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: provide IP-related API on any OS
net: replace Windows networking shim
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 - examples/cmdline/parse_obj_list.c | 2 - lib/librte_cmdline/cmdline.c | 5 - lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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 | 5 +- lib/librte_eal/common/eal_internal_cfg.h | 1 + lib/librte_eal/common/eal_private.h | 11 +++ .../freebsd/include/rte_os_internal.h | 14 +++ lib/librte_eal/include/rte_thread.h | 11 +++ .../linux/include/rte_os_internal.h | 14 +++ lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 3 + lib/librte_eal/windows/eal.c | 30 ++++++ 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/eal_thread.c | 9 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ------ lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 -- lib/librte_eal/windows/include/rte_os.h | 92 +------------------ .../windows/include/rte_os_internal.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 13 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 49 files changed, 202 insertions(+), 254 deletions(-) create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.2
PATCH v5 1/5 eal: add sleep API
POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +3 -0
@@ -419,6 +419,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL {
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v5 1/5] eal: add sleep API
Quoted 14 lines · Dmitry Kozlyuk
POSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-)
[SNIP]
PATCH v5 2/5 eal/windows: hide asprintf() shim
In reply to Dmitry KozlyukMake asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
lib/librte_eal/common/eal_private.h +11 -0
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.2
PATCH v5 3/5 eal: make OS shims internal
In reply to Dmitry KozlyukDPDK 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 <rte_os.h> 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 all shims to <rte_os_internal.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>.
--- 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_internal_cfg.h | 1 + .../freebsd/include/rte_os_internal.h | 14 +++ .../linux/include/rte_os_internal.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 | 92 +------------------ .../windows/include/rte_os_internal.h | 28 ++++++ lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_kvargs/rte_kvargs.c | 1 + 21 files changed, 77 insertions(+), 104 deletions(-) create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h
drivers/bus/pci/private.h +3 -1
@@ -7,8 +7,10 @@#include <stdbool.h> #include <stdio.h> -#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_os_internal.h> +#include <rte_pci.h> extern struct rte_pci_bus rte_pci_bus;
drivers/bus/vdev/vdev_private.h +2 -0
@@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include <rte_os_internal.h> + #ifdef __cplusplus extern "C" { #endif
drivers/common/mlx5/mlx5_common.h +1 -0
@@ -14,6 +14,7 @@#include <rte_kvargs.h> #include <rte_devargs.h> #include <rte_bitops.h> +#include <rte_os_internal.h> #include "mlx5_prm.h" #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -27,6 +27,7 @@#include <rte_tailq.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h> #include "i40e_logs.h" #include "base/i40e_prototype.h"
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
@@ -4,8 +4,6 @@#include <io.h> -#include <rte_os.h> -#include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
@@ -8,6 +8,7 @@#include <stdarg.h> #include <rte_common.h> +#include <rte_os_internal.h> #ifdef RTE_EXEC_ENV_WINDOWS #include <rte_windows.h> #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_config.c +0 -1
@@ -3,7 +3,6 @@*/ #include <string.h> -#include <rte_os.h> #include <rte_string_fns.h> #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -11,6 +11,7 @@#define EAL_INTERNAL_CFG_H #include <rte_eal.h> +#include <rte_os_internal.h> #include <rte_pci_dev_feature_defs.h> #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_internal.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/linux/include/rte_os_internal.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
@@ -6,7 +6,6 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_memzone.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
@@ -9,7 +9,6 @@#include <rte_common.h> #include <rte_debug.h> #include <rte_lcore.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
@@ -3,7 +3,6 @@*/ #include <rte_errno.h> -#include <rte_os.h> #include "eal_internal_cfg.h" #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -88
112 lines not on this page · raw message
lib/librte_eal/windows/include/rte_os_internal.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @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_INTERNAL_H_ */
lib/librte_ethdev/ethdev_private.h +2 -0
@@ -5,6 +5,8 @@#ifndef _ETH_PRIVATE_H_#define _ETH_PRIVATE_H_ +#include <rte_os_internal.h> +#include "rte_ethdev.h" #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
@@ -6,6 +6,7 @@#include <string.h> #include <stdlib.h> +#include <rte_os_internal.h> #include <rte_string_fns.h> #include "rte_kvargs.h"
Signature · 1 line
2.29.2
PATCH v5 4/5 net: provide IP-related API on any OS
In reply to Dmitry KozlyukUsers of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constatns, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.
Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX include in components enabled on Windows.
--- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_flow.c | 4 ++-- drivers/net/mlx5/mlx5_flow.h | 4 ++-- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 ----- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ------ lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ------ lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_ethdev/rte_ethdev.c | 13 +++++-------- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 3 +++ 14 files changed, 14 insertions(+), 38 deletions(-)
drivers/net/mlx5/mlx5.h +1 -1
@@ -10,7 +10,7 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> +#include <sys/queue.h> #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +2 -2
@@ -3,13 +3,13 @@* Copyright 2016 Mellanox Technologies, Ltd */ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +#include <sys/queue.h> +#include <rte_common.h> #include <rte_ether.h> #include <ethdev_driver.h>
drivers/net/mlx5/mlx5_flow.h +2 -2
@@ -5,12 +5,12 @@#ifndef RTE_PMD_MLX5_FLOW_H_ #define RTE_PMD_MLX5_FLOW_H_ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> +#include <sys/queue.h> +#include <rte_alarm.h> #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
@@ -8,7 +8,6 @@#include <string.h> #include <inttypes.h> #include <errno.h> -#include <netinet/in.h> #include <rte_ether.h> #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
@@ -8,12 +8,7 @@#include <stdint.h> #include <string.h> #include <stdlib.h> -#include <stdarg.h> #include <errno.h> -#include <netinet/in.h> -#ifdef RTE_EXEC_ENV_FREEBSD -#include <sys/socket.h> -#endif #include <cmdline_rdline.h> #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
@@ -6,11 +6,9 @@#include <stdio.h> #include <inttypes.h> -#include <stdarg.h> #include <errno.h> #include <ctype.h> #include <string.h> -#include <netinet/in.h> #include <cmdline_parse.h> #include <cmdline_parse_ipaddr.h>
lib/librte_cmdline/cmdline.c +0 -1
@@ -12,7 +12,6 @@#include <inttypes.h> #include <fcntl.h> #include <errno.h> -#include <netinet/in.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse.c +0 -2
@@ -11,8 +11,6 @@#include <inttypes.h> #include <ctype.h> -#include <netinet/in.h> -#include <rte_string_fns.h> #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
@@ -5,13 +5,7 @@*/ #include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> -#include <sys/types.h> #include <rte_string_fns.h> #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
@@ -6,14 +6,8 @@#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> #include <errno.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
@@ -8,7 +8,7 @@#define _PARSE_IPADDR_H_#include <cmdline_parse.h> -#include <netinet/in.h> +#include <rte_ip.h> #ifdef __cplusplusextern "C" {
lib/librte_ethdev/rte_ethdev.c +5 -8
@@ -2,18 +2,15 @@* Copyright(c) 2010-2017 Intel Corporation */ -#include <sys/types.h> -#include <sys/queue.h> #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdint.h> -#include <inttypes.h> -#include <netinet/in.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/queue.h> #include <rte_byteorder.h> #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
@@ -6,7 +6,6 @@#define _RTE_ETHDEV_CORE_H_#include <pthread.h> -#include <sys/types.h> /** * @file
lib/librte_net/rte_ip.h +3 -0
@@ -16,7 +16,10 @@*/ #include <stdint.h> + +#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h>
Signature · 1 line
2.29.2
PATCH v5 5/5 net: replace Windows networking shim
In reply to Dmitry KozlyukRemove networking shim from Windows EAL.
Replace it with system headers with two workarounds:
1. Windows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with s_addr field of struct rte_ether_hdr. Undefining this macro in <rte_ether.h> had been breaking some usages of DPDK and Windows headers in one file.
Renaming is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro.
2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.
--- drivers/net/i40e/i40e_fdir.c | 1 + lib/librte_eal/windows/include/arpa/inet.h | 30 --------------- lib/librte_eal/windows/include/netinet/in.h | 38 ------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ----- .../windows/include/rte_os_internal.h | 8 ++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------ lib/librte_net/rte_ether.h | 26 ++++++++++--- lib/librte_net/rte_ip.h | 4 ++ lib/librte_net/rte_net.c | 1 + 9 files changed, 34 insertions(+), 108 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h> #include "i40e_logs.h" #include "base/i40e_type.h"
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _ARPA_INET_H_ -#define _ARPA_INET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <netinet/in.h> -#include <sys/socket.h> - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -int -inet_pton (int af,const char *src,void *dst); - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -const char * -inet_ntop (int af,const void *src,char *dst,socklen_t size); - -#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IN_H_ -#define _IN_H_ - -#include <stdint.h> -#include <sys/socket.h> - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_SCTP 132 - -#define INET6_ADDRSTRLEN 46 - -struct in_addr { -uint32_t s_addr; -}; - -struct in6_addr { -uint8_t s6_addr[16 ]; -}; - -#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
@@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IP_H_ -#define _IP_H_ - -#define IPVERSION 4 - -#endif
lib/librte_eal/windows/include/rte_os_internal.h +8 -0
@@ -25,4 +25,12 @@#define close (fd) _close(fd)#define unlink (path) _unlink(path) +#define IPVERSION 4 + +#define IPPROTO_IPIP 4 +#define IPPROTO_GRE 47 +#ifdef RTE_TOOLCHAIN_GCC +#define IPPROTO_SCTP 132 +#endif +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <stddef.h> - -#define AF_INET 2 -#define AF_INET6 23 - -typedef size_t socklen_t ; - -#endif /* _SYS_SOCKET_H_ */
lib/librte_net/rte_ether.h +20 -6
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +/* Windows Sockets headers contain `#define s_addr S_un.S_addr`. +* Temporarily disable this macro to avoid conflict at definition. +* Place source MAC address in both `s_addr` and `S_un.S_addr` fields, +* so that access works either directly or through the macro. +*/ +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif +/** * Ethernet header: Contains the destination address, source address * and frame type. */ struct rte_ether_hdr {struct rte_ether_addr d_addr;/**< Destination address. */ -struct rte_ether_addr s_addr;/**< Source address. */ -uint16_t ether_type;/**< Frame type. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_addr; + } S_un;/**< Do not use directly; use s_addr instead.*/ + }; +uint16_t ether_type;/**< Frame type. */ }__rte_aligned (2 ); +#pragma pop_macro("s_addr") +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
lib/librte_net/rte_ip.h +4 -0
@@ -17,11 +17,15 @@#include <stdint.h> +#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else #include <sys/socket.h> #include <sys/types.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif #include <rte_byteorder.h> #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_internal.h> /* get l3 packet type from ip6 next protocol */ static uint32_t
Signature · 1 line
2.29.2
v6 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v6:
* Rebase on ToT to resolve conflicts.
v5:
* Unify series with removing Windows networking shim to eliminate dependency between series and CI failures.
* RTE_BUILD_INTERNAL -> rte_os_internal.h (Thomas Monjalon).
* Remove release notes: hidden symbols were never part of API.
Dmitry Kozlyuk (5):
eal: add sleep API
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: provide IP-related API on any OS
net: replace Windows networking shim
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 - examples/cmdline/parse_obj_list.c | 2 - lib/librte_cmdline/cmdline.c | 5 - lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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 | 5 +- lib/librte_eal/common/eal_internal_cfg.h | 1 + lib/librte_eal/common/eal_private.h | 11 +++ .../freebsd/include/rte_os_internal.h | 14 +++ lib/librte_eal/include/rte_thread.h | 11 +++ .../linux/include/rte_os_internal.h | 14 +++ lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 +- lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal.c | 30 ++++++ 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/eal_thread.c | 9 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ------ lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 -- lib/librte_eal/windows/include/rte_os.h | 92 +------------------ .../windows/include/rte_os_internal.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 13 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 49 files changed, 200 insertions(+), 254 deletions(-) create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.3
PATCH v6 1/5 eal: add sleep API
POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 34 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);__rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +1 -0
@@ -415,6 +415,7 @@ EXPERIMENTAL { rte_thread_tls_value_set; # added in 21.05 + rte_thread_sleep; rte_version_minor; rte_version_month; rte_version_prefix;
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.3
PATCH v6 2/5 eal/windows: hide asprintf() shim
In reply to Dmitry KozlyukMake asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
lib/librte_eal/common/eal_private.h +11 -0
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim
20/03/2021 14:05, Dmitry Kozlyuk:
Quoted 11 lines
Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need
asprintf()and also because callers from other modules would have no reliable way to free allocated memory.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>--- lib/librte_eal/common/eal_private.h | 11 +++++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
It would be logic to remove the asprintf implementation from rte_os.h in this patch.
PATCH v6 3/5 eal: make OS shims internal
In reply to Dmitry KozlyukDPDK 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 <rte_os.h> 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 all shims to <rte_os_internal.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>.
--- 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_internal_cfg.h | 1 + .../freebsd/include/rte_os_internal.h | 14 +++ .../linux/include/rte_os_internal.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 | 92 +------------------ .../windows/include/rte_os_internal.h | 28 ++++++ lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_kvargs/rte_kvargs.c | 1 + 21 files changed, 77 insertions(+), 104 deletions(-) create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h
drivers/bus/pci/private.h +3 -1
@@ -7,8 +7,10 @@#include <stdbool.h> #include <stdio.h> -#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_os_internal.h> +#include <rte_pci.h> extern struct rte_pci_bus rte_pci_bus;
drivers/bus/vdev/vdev_private.h +2 -0
@@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include <rte_os_internal.h> + #ifdef __cplusplus extern "C" { #endif
drivers/common/mlx5/mlx5_common.h +1 -0
@@ -14,6 +14,7 @@#include <rte_kvargs.h> #include <rte_devargs.h> #include <rte_bitops.h> +#include <rte_os_internal.h> #include "mlx5_prm.h" #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -27,6 +27,7 @@#include <rte_tailq.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h> #include "i40e_logs.h" #include "base/i40e_prototype.h"
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
@@ -4,8 +4,6 @@#include <io.h> -#include <rte_os.h> -#include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
@@ -8,6 +8,7 @@#include <stdarg.h> #include <rte_common.h> +#include <rte_os_internal.h> #ifdef RTE_EXEC_ENV_WINDOWS #include <rte_windows.h> #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_config.c +0 -1
@@ -3,7 +3,6 @@*/ #include <string.h> -#include <rte_os.h> #include <rte_string_fns.h> #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -11,6 +11,7 @@#define EAL_INTERNAL_CFG_H #include <rte_eal.h> +#include <rte_os_internal.h> #include <rte_pci_dev_feature_defs.h> #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_internal.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/linux/include/rte_os_internal.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
@@ -6,7 +6,6 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_memzone.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
@@ -9,7 +9,6 @@#include <rte_common.h> #include <rte_debug.h> #include <rte_lcore.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
@@ -3,7 +3,6 @@*/ #include <rte_errno.h> -#include <rte_os.h> #include "eal_internal_cfg.h" #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -88
112 lines not on this page · raw message
lib/librte_eal/windows/include/rte_os_internal.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_INTERNAL_H_ +#define _RTE_OS_INTERNAL_H_ + +#include <rte_os.h> + +/** +* @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_INTERNAL_H_ */
lib/librte_ethdev/ethdev_private.h +2 -0
@@ -5,6 +5,8 @@#ifndef _ETH_PRIVATE_H_#define _ETH_PRIVATE_H_ +#include <rte_os_internal.h> +#include "rte_ethdev.h" #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
@@ -6,6 +6,7 @@#include <string.h> #include <stdlib.h> +#include <rte_os_internal.h> #include <rte_string_fns.h> #include "rte_kvargs.h"
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
20/03/2021 14:05, Dmitry Kozlyuk:
Quoted 9 lines
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 <
rte_os.h> 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 all shims to <
rte_os_internal.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>.
This shim could have been convenient for applications. If not named "internal", we could export the header file and allow apps including it.
Otherwise the app can recreate this file on its side, it is not a big deal.
Opinions?
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
Quoted 8 lines
This shim could have been convenient for applications. If not named "internal", we could export the header file and allow apps including it.
Otherwise the app can recreate this file on its side, it is not a big deal.
Opinions?
Based on my experience with SPDK, I believe this would get messy very quickly.
For example, a common usage is to redefine close to _close. If the application is going to use sockets without requiring changes, then a fake fd is needed to represent a socket and close has to handle it as well ... which will clash with the 'simplistic' redefinition to _close, so we'd need some way of turning these on/off individually.
I think there are really only two models that are viable - either an external POSIX layer that is used by everything (in the general case, Cygwin would be an example), or a private implementation that is not exposed publicly.
Keeping the implementation private is not just about keeping POSIX out of the headers. It's about avoiding conflicts with the application; e.g. making sure that any signal implementation can co-exist with the application.
Regards,
Nick
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
31/03/2021 23:05, Nick Connolly:
Quoted 23 lines
Quoted 8 lines
This shim could have been convenient for applications. If not named "internal", we could export the header file and allow apps including it.
Otherwise the app can recreate this file on its side, it is not a big deal.
Opinions?Based on my experience with SPDK, I believe this would get messy very quickly.
For example, a common usage is to redefine close to
_close. If the application is going to use sockets without requiring changes, then a fake fd is needed to represent a socket and close has to handle it as well ... which will clash with the 'simplistic' redefinition to_close, so we'd need some way of turning these on/off individually.I think there are really only two models that are viable - either an external POSIX layer that is used by everything (in the general case, Cygwin would be an example), or a private implementation that is not exposed publicly.
Quoted 4 lines
Keeping the implementation private is not just about keeping POSIX out of the headers. It's about avoiding conflicts with the application; e.g. making sure that any signal implementation can co-exist with the application.
I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim for their convenience in case they are fully based on DPDK and understand the risk of conflict with some other code.
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
Quoted 5 lines
I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim for their convenience in case they are fully based on DPDK and understand the risk of conflict with some other code.
Agreed - there’s no harm in doing so.
My point was simply that for a non-trivial application I suspect it will have limited value due to the sorts of conflicts that are likely to arise.
Regards,
Nick
Quoted 1 line
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
31/03/2021 23:45, Nick Connolly:
Quoted 11 lines
Quoted 5 lines
I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim for their convenience in case they are fully based on DPDK and understand the risk of conflict with some other code.Agreed - there’s no harm in doing so.
My point was simply that for a non-trivial application I suspect it will have limited value due to the sorts of conflicts that are likely to arise.
OK yes.
If we expose this header, we should bring it with a disclaimer.
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
2021-03-31 23:55 (UTC+0200), Thomas Monjalon:
Quoted 8 lines
31/03/2021 23:45, Nick Connolly:
Quoted 7 lines
Quoted 5 lines
I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim for their convenience in case they are fully based on DPDK and understand the risk of conflict with some other code.
Quoted 7 lines
Quoted 4 lines
Agreed - there’s no harm in doing so.
My point was simply that for a non-trivial application I suspect it will have limited value due to the sorts of conflicts that are likely to arise.
OK yes.
If we expose this header, we should bring it with a disclaimer.
Let's now avoid "internal" (rte_os_shim?), but expose it later, if ever:
1. The concept of "not so public" API is new, probably a techboard subject.
2. We may want devtools checks against including it from public headers.
Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
02/04/2021 01:10, Dmitry Kozlyuk:
Quoted 14 lines
2021-03-31 23:55 (UTC+0200), Thomas Monjalon:
Quoted 13 lines
31/03/2021 23:45, Nick Connolly:
Quoted 11 lines
Quoted 5 lines
I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim for their convenience in case they are fully based on DPDK and understand the risk of conflict with some other code.Agreed - there’s no harm in doing so.
My point was simply that for a non-trivial application I suspect it will have limited value due to the sorts of conflicts that are likely to arise.
Quoted 7 lines
Quoted 2 lines
OK yes.
If we expose this header, we should bring it with a disclaimer.Let's now avoid "internal" (
rte_os_shim?), but expose it later, if ever:1. The concept of "not so public" API is new, probably a techboard subject.
2. We may want devtools checks against including it from public headers.
Yes it should be well discussed and checked with scripts. For now, let's not expose such shim, but as you said, adopt a more descriptive name avoiding "internal" qualifier.
PATCH v6 4/5 net: provide IP-related API on any OS
In reply to Dmitry KozlyukUsers of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constatns, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.
Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX include in components enabled on Windows.
--- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_flow.c | 4 ++-- drivers/net/mlx5/mlx5_flow.h | 4 ++-- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 ----- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ------ lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ------ lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_ethdev/rte_ethdev.c | 13 +++++-------- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 3 +++ 14 files changed, 14 insertions(+), 38 deletions(-)
drivers/net/mlx5/mlx5.h +1 -1
@@ -10,7 +10,7 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> +#include <sys/queue.h> #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +2 -2
@@ -3,13 +3,13 @@* Copyright 2016 Mellanox Technologies, Ltd */ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +#include <sys/queue.h> +#include <rte_common.h> #include <rte_ether.h> #include <ethdev_driver.h>
drivers/net/mlx5/mlx5_flow.h +2 -2
@@ -5,12 +5,12 @@#ifndef RTE_PMD_MLX5_FLOW_H_ #define RTE_PMD_MLX5_FLOW_H_ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> +#include <sys/queue.h> +#include <rte_alarm.h> #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
@@ -8,7 +8,6 @@#include <string.h> #include <inttypes.h> #include <errno.h> -#include <netinet/in.h> #include <rte_ether.h> #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
@@ -8,12 +8,7 @@#include <stdint.h> #include <string.h> #include <stdlib.h> -#include <stdarg.h> #include <errno.h> -#include <netinet/in.h> -#ifdef RTE_EXEC_ENV_FREEBSD -#include <sys/socket.h> -#endif #include <cmdline_rdline.h> #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
@@ -6,11 +6,9 @@#include <stdio.h> #include <inttypes.h> -#include <stdarg.h> #include <errno.h> #include <ctype.h> #include <string.h> -#include <netinet/in.h> #include <cmdline_parse.h> #include <cmdline_parse_ipaddr.h>
lib/librte_cmdline/cmdline.c +0 -1
@@ -12,7 +12,6 @@#include <inttypes.h> #include <fcntl.h> #include <errno.h> -#include <netinet/in.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse.c +0 -2
@@ -11,8 +11,6 @@#include <inttypes.h> #include <ctype.h> -#include <netinet/in.h> -#include <rte_string_fns.h> #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
@@ -5,13 +5,7 @@*/ #include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> -#include <sys/types.h> #include <rte_string_fns.h> #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
@@ -6,14 +6,8 @@#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> #include <errno.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
@@ -8,7 +8,7 @@#define _PARSE_IPADDR_H_#include <cmdline_parse.h> -#include <netinet/in.h> +#include <rte_ip.h> #ifdef __cplusplusextern "C" {
lib/librte_ethdev/rte_ethdev.c +5 -8
@@ -2,18 +2,15 @@* Copyright(c) 2010-2017 Intel Corporation */ -#include <sys/types.h> -#include <sys/queue.h> #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdint.h> -#include <inttypes.h> -#include <netinet/in.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/queue.h> #include <rte_byteorder.h> #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
@@ -6,7 +6,6 @@#define _RTE_ETHDEV_CORE_H_#include <pthread.h> -#include <sys/types.h> /** * @file
lib/librte_net/rte_ip.h +3 -0
@@ -16,7 +16,10 @@*/ #include <stdint.h> + +#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h>
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS
20/03/2021 14:05, Dmitry Kozlyuk:
Quoted 2 lines
Users of <
rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constatns, but still had to include POSIX headers
typo: constants
Quoted 7 lines
for
inet_pton()and other standard IP-related facilities.Extend <
rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX include in components enabled on Windows.Signed-off-by Dmitry Kozlyuk <[email protected]>
[...]
drivers/net/mlx5/mlx5.h line 14
Quoted 9 lines
drivers/net/mlx5/mlx5.h +1
-1@@ -10,7 +10,7 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> +#include <sys/queue.h>
No need of blank space between system includes.
(same comments for other files)
lib/librte_net/rte_ip.h
Quoted 4 lines
lib/librte_net/rte_ip.h +1
-0#include <stdint.h> +
That's an unneeded blank line.
lib/librte_net/rte_ip.h line 24
Quoted 5 lines
lib/librte_net/rte_ip.h +2
-0+#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h>
The benefit is not obvious because the removal of Windows code is done in another patch.
Please could you re-arrange the patch to be more atomic?
PATCH v6 5/5 net: replace Windows networking shim
In reply to Dmitry KozlyukRemove networking shim from Windows EAL.
Replace it with system headers with two workarounds:
1. Windows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with s_addr field of struct rte_ether_hdr. Undefining this macro in <rte_ether.h> had been breaking some usages of DPDK and Windows headers in one file.
Renaming is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro.
2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.
--- drivers/net/i40e/i40e_fdir.c | 1 + lib/librte_eal/windows/include/arpa/inet.h | 30 --------------- lib/librte_eal/windows/include/netinet/in.h | 38 ------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ----- .../windows/include/rte_os_internal.h | 8 ++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------ lib/librte_net/rte_ether.h | 26 ++++++++++--- lib/librte_net/rte_ip.h | 4 ++ lib/librte_net/rte_net.c | 1 + 9 files changed, 34 insertions(+), 108 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h> #include "i40e_logs.h" #include "base/i40e_type.h"
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _ARPA_INET_H_ -#define _ARPA_INET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <netinet/in.h> -#include <sys/socket.h> - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -int -inet_pton (int af,const char *src,void *dst); - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -const char * -inet_ntop (int af,const void *src,char *dst,socklen_t size); - -#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IN_H_ -#define _IN_H_ - -#include <stdint.h> -#include <sys/socket.h> - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_SCTP 132 - -#define INET6_ADDRSTRLEN 46 - -struct in_addr { -uint32_t s_addr; -}; - -struct in6_addr { -uint8_t s6_addr[16 ]; -}; - -#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
@@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IP_H_ -#define _IP_H_ - -#define IPVERSION 4 - -#endif
lib/librte_eal/windows/include/rte_os_internal.h +8 -0
@@ -25,4 +25,12 @@#define close (fd) _close(fd)#define unlink (path) _unlink(path) +#define IPVERSION 4 + +#define IPPROTO_IPIP 4 +#define IPPROTO_GRE 47 +#ifdef RTE_TOOLCHAIN_GCC +#define IPPROTO_SCTP 132 +#endif +#endif /* _RTE_OS_INTERNAL_H_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <stddef.h> - -#define AF_INET 2 -#define AF_INET6 23 - -typedef size_t socklen_t ; - -#endif /* _SYS_SOCKET_H_ */
lib/librte_net/rte_ether.h +20 -6
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +/* Windows Sockets headers contain `#define s_addr S_un.S_addr`. +* Temporarily disable this macro to avoid conflict at definition. +* Place source MAC address in both `s_addr` and `S_un.S_addr` fields, +* so that access works either directly or through the macro. +*/ +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif +/** * Ethernet header: Contains the destination address, source address * and frame type. */ struct rte_ether_hdr {struct rte_ether_addr d_addr;/**< Destination address. */ -struct rte_ether_addr s_addr;/**< Source address. */ -uint16_t ether_type;/**< Frame type. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_addr; + } S_un;/**< Do not use directly; use s_addr instead.*/ + }; +uint16_t ether_type;/**< Frame type. */ }__rte_aligned (2 ); +#pragma pop_macro("s_addr") +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
lib/librte_net/rte_ip.h +4 -0
@@ -17,11 +17,15 @@#include <stdint.h> +#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else #include <sys/socket.h> #include <sys/types.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif #include <rte_byteorder.h> #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_internal.h> /* get l3 packet type from ip6 next protocol */ static uint32_t
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim
20/03/2021 14:05, Dmitry Kozlyuk:
Quoted 8 lines
Remove networking shim from Windows EAL.
Replace it with system headers with two workarounds:
1. Windows Sockets headers contain
#define s_addr S_un.S_addr, which conflicts withs_addrfield ofstruct rte_ether_hdr. Undefining this macro in <rte_ether.h> had been breaking some usages of DPDK and Windows headers in one file.
I don't understand this last sentence.
Quoted 8 lines
Renaming is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.htmlTemporarily disable
s_addrmacro aroundstruct rte_ether_hdrdefinition to avoid conflict. Place source MAC address in boths_addrandS_un.S_addrfields, so that access works either directly or through the macro.
It could be a patch in itself.
Quoted 2 lines
2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.
I think it belongs to previous patch about extending the IP-related API.
drivers/net/i40e/i40e_fdir.c line 25
Quoted 7 lines
drivers/net/i40e/i40e_fdir.c +1
-0@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h>
Why is it needed?
[...]
Quoted 5 lines
lib/librte_net/rte_ip.h +0
-0@@ -17,11 +17,15 @@#include <stdint.h>
lib/librte_net/rte_ip.h line 28
Quoted 10 lines
lib/librte_net/rte_ip.h +4
-0+#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else #include <sys/socket.h> #include <sys/types.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif
Should be in previous patch about extending IP API to any OS.
lib/librte_net/rte_net.c line 18
Quoted 7 lines
lib/librte_net/rte_net.c +1
-0@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_internal.h>
Why is it needed?
Re: [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim
2021-03-26 10:28 (UTC+0100), Thomas Monjalon:
Quoted 1 line
20/03/2021 14:05, Dmitry Kozlyuk:
[...]
Quoted 9 lines
drivers/net/i40e/i40e_fdir.c line 25
Quoted 7 lines
drivers/net/i40e/i40e_fdir.c +1
-0@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_internal.h> Why is it needed?
I deliberately put all shim definitions, like missing IPPROTO_* constants that are used in this file, in <rte_os_internal.h> so that they are never exposed to DPDK users. Other inclusions of this file have the same reason.
v7 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v7:
* Rearrange patches, improve wording, fix typo.
* rte_os_internal.h -> rte_os_shim.h for possible later exposure
* Remove unnecessary blank lines.
Dmitry Kozlyuk (5):
eal: add sleep API
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 -- examples/cmdline/parse_obj_list.c | 2 - lib/librte_cmdline/cmdline.c | 5 -- lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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 | 5 +- lib/librte_eal/common/eal_internal_cfg.h | 1 + lib/librte_eal/common/eal_private.h | 11 +++ lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++ lib/librte_eal/include/rte_thread.h | 11 +++ lib/librte_eal/linux/include/rte_os_shim.h | 14 +++ lib/librte_eal/rte_eal_exports.def | 2 + lib/librte_eal/unix/rte_thread.c | 10 ++- lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal.c | 30 +++++++ 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/eal_thread.c | 9 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ------- lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 --- lib/librte_eal/windows/include/rte_os.h | 92 +------------------- lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 12 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 49 files changed, 196 insertions(+), 255 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 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.3
PATCH v7 1/5 eal: add sleep API
POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.
--- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 34 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_timer.c +3 -2
@@ -16,6 +16,7 @@#include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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_thread_sleep(1) will sleep for 1 second */ uint64_t start =rte_rdtsc (); -sleep (1 ); +rte_thread_sleep (1 );/* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR (rte_rdtsc () - start,CYC_PER_10MHZ ); }
lib/librte_eal/include/rte_thread.h +11 -0
@@ -119,6 +119,17 @@ int rte_thread_value_set(rte_thread_key key, const void *value);__rte_experimental void *rte_thread_value_get(rte_thread_key key); +/** +* Suspend current OS thread for the specified time, yielding CPU to scheduler. +* +* @param sec +* Number of seconds to sleep. The system may return control later, +* but not earlier. Zero value always yields the CPU, but control may be +* returned immediately. +*/ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus }#endif
lib/librte_eal/rte_eal_exports.def +2 -0
@@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep
lib/librte_eal/unix/rte_thread.c +9 -1
@@ -3,10 +3,12 @@*/ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <rte_common.h> #include <rte_errno.h> #include <rte_log.h>
@@ -90,3 +92,9 @@ rte_thread_value_get(rte_thread_key key) }return pthread_getspecific (key->thread_index); } + +void +rte_thread_sleep (unsigned int sec) +{ +sleep (sec); +}
lib/librte_eal/version.map +1 -0
@@ -413,6 +413,7 @@ EXPERIMENTAL { # added in 21.05 rte_thread_key_create; rte_thread_key_delete; + rte_thread_sleep; rte_thread_value_get; rte_thread_value_set; rte_version_minor;
lib/librte_eal/windows/eal_thread.c +8 -1
@@ -11,9 +11,10 @@#include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)/* This is a stub, not the expected result */ return 0 ; } + +void +rte_thread_sleep (unsigned int sec) +{ +return Sleep (MS_PER_S * sec); +}
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
Quoted 9 lines
From: dev [mailto:[email protected]] On Behalf Of Dmitry Kozlyuk
Sent: Sunday, April 4, 2021 1:41 AMPOSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>Acked-by Ray Kinsella <[email protected]>
How is this better than the rte_delay_us_sleep() function in rte_cycles.h?
Med venlig hilsen / kind regards
- Morten Brørup
Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
2021-04-06 16:34 (UTC+0200), Morten Brørup:
Quoted 11 lines
Quoted 9 lines
From: dev [mailto:[email protected]] On Behalf Of Dmitry Kozlyuk
Sent: Sunday, April 4, 2021 1:41 AMPOSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>Acked-by Ray Kinsella <[email protected]>How is this better than the
rte_delay_us_sleep()function inrte_cycles.
Honestly, I just assumed the sleep() shim existed for a reason. Now that you pointed to it, I think indeed no new API is needed.
I wonder why rte_delay_us_sleep() is not used throughout DPDK. Should their usages be converted as soon as code is enabled for Windows?
Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
Quoted 14 lines
From: dev [mailto:[email protected]] On Behalf Of Dmitry Kozlyuk
Sent: Wednesday, April 7, 2021 1:30 AM2021-04-06 16:34 (UTC+0200), Morten Brørup:
Quoted 10 lines
Quoted 9 lines
From: dev [mailto:[email protected]] On Behalf Of Dmitry Kozlyuk
Sent: Sunday, April 4, 2021 1:41 AMPOSIX sleep(3) is missing from Windows.
Add genericrte_thread_sleep()to suspend current OS thread.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>Acked-by Ray Kinsella <[email protected]>
Quoted 7 lines
Quoted 1 line
How is this better than the
rte_delay_us_sleep()function in
rte_cycles.Honestly, I just assumed the
sleep()shim existed for a reason. Now that you pointed to it, I think indeed no new API is needed.I wonder why
rte_delay_us_sleep()is not used throughout DPDK.
I think it's just tradition from Linux/BSD developers not being used to cross-platform development or having forgotten how to develop software for deeply embedded systems without a standard O/S below. We use POSIX functions like sleep() without thinking about it, and simply forget looking for an EAL variant of the function first.
Quoted 2 lines
Should their usages be converted as soon as code is enabled for Windows?
Yes. The Environment Abstraction Layer is there to avoid using O/S specific function calls. So it should be safe to replace all these sleep() calls with the EAL variant at any time.
Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
Quoted 3 lines · Morten Brørup
I think it's just tradition from Linux/BSD developers not being used to cross-platform development or having forgotten how to develop software for deeply embedded systems without a standard O/S below. We use POSIX functions like
sleep()without thinking about it, and simply forget looking for an EAL variant of the function first.
it's easy to make this mistake if by including dpdk application headers we indirectly introduce platform specific headers into the applications namespace.
if this wasn't happening the application would be forced to confront the issue by directly including unistd.h itself directly making it more obvious that they were writing inherently non-portable code.
i think this is being fixed but it is a work in progress but it highlights the reason why there needs to be scrutiny around what goes into the eal and other library headers.
PATCH v7 2/5 eal/windows: hide asprintf() shim
In reply to Dmitry KozlyukMake asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++ lib/librte_eal/windows/include/rte_os.h | 30 ------------------------- 3 files changed, 41 insertions(+), 30 deletions(-)
lib/librte_eal/common/eal_private.h +11 -0
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
lib/librte_eal/windows/include/rte_os.h +0 -30
@@ -10,7 +10,6 @@* which is not supported natively or named differently in Windows. */ -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {typedef long long ssize_t ;#ifndef RTE_TOOLCHAIN_GCC - -static inline int -asprintf (char **buffer,const char *format, ...) -{ -int size, ret; -va_list arg; - -va_start (arg, format); - size =vsnprintf (NULL ,0 , format, arg); -va_end (arg); -if (size <0 ) -return -1 ; - size++; - - *buffer = (char *)malloc (size); -if (*buffer ==NULL ) -return -1 ; - -va_start (arg, format); - ret =vsnprintf (*buffer, size, format, arg); -va_end (arg); -if (ret != size -1 ) { -free (*buffer); -return -1 ; - } -return ret; -} -static inline const char *eal_strerror (int code) {
@@ -111,7 +82,6 @@ eal_strerror(int code)#ifndef strerror#define strerror eal_strerror#endif -#endif /* RTE_TOOLCHAIN_GCC */ #ifdef __cplusplus
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim
Quoted 8 lines
Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need
asprintf()and also because callers from other modules would have no reliable way to free allocated memory.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Khoa To <[email protected]>
PATCH v7 3/5 eal: make OS shims internal
In reply to Dmitry KozlyukDPDK 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 <rte_os.h> 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 all shims to <rte_os_shim.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>.
--- 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_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 + 21 files changed, 77 insertions(+), 74 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
drivers/bus/pci/private.h +3 -1
@@ -7,8 +7,10 @@#include <stdbool.h> #include <stdio.h> -#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_os_shim.h> +#include <rte_pci.h> extern struct rte_pci_bus rte_pci_bus;
drivers/bus/vdev/vdev_private.h +2 -0
@@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include <rte_os_shim.h> + #ifdef __cplusplus extern "C" { #endif
drivers/common/mlx5/mlx5_common.h +1 -0
@@ -14,6 +14,7 @@#include <rte_kvargs.h> #include <rte_devargs.h> #include <rte_bitops.h> +#include <rte_os_shim.h> #include "mlx5_prm.h" #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -27,6 +27,7 @@#include <rte_tailq.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_prototype.h"
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
@@ -4,8 +4,6 @@#include <io.h> -#include <rte_os.h> -#include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
@@ -8,6 +8,7 @@#include <stdarg.h> #include <rte_common.h> +#include <rte_os_shim.h> #ifdef RTE_EXEC_ENV_WINDOWS #include <rte_windows.h> #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_config.c +0 -1
@@ -3,7 +3,6 @@*/ #include <string.h> -#include <rte_os.h> #include <rte_string_fns.h> #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -11,6 +11,7 @@#define EAL_INTERNAL_CFG_H #include <rte_eal.h> +#include <rte_os_shim.h> #include <rte_pci_dev_feature_defs.h> #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/linux/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
@@ -6,7 +6,6 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_memzone.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
@@ -9,7 +9,6 @@#include <rte_common.h> #include <rte_debug.h> #include <rte_lcore.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
@@ -3,7 +3,6 @@*/ #include <rte_errno.h> -#include <rte_os.h> #include "eal_internal_cfg.h" #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -58
76 lines not on this page · raw message
lib/librte_eal/windows/include/rte_os_shim.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @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_ */
lib/librte_ethdev/ethdev_private.h +2 -0
@@ -5,6 +5,8 @@#ifndef _ETH_PRIVATE_H_#define _ETH_PRIVATE_H_ +#include <rte_os_shim.h> +#include "rte_ethdev.h" #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
@@ -7,6 +7,7 @@#include <stdlib.h> #include <stdbool.h> +#include <rte_os_shim.h> #include <rte_string_fns.h> #include "rte_kvargs.h"
Signature · 1 line
2.29.3
PATCH v7 4/5 net: work around s_addr macro on Windows
In reply to Dmitry KozlyukWindows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with definition of s_addr field of struct rte_ether_hdr. Prieviously s_addr was undefined in <rte_ether.h>, which had been breaking access to s_addr field of struct in_addr, so some DPDK and Windows headers could not be included in one file.
Renaming of struct rte_ether_hdr is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro as defined in Windows headers.
--- lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
lib/librte_net/rte_ether.h +20 -6
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +/* Windows Sockets headers contain `#define s_addr S_un.S_addr`. +* Temporarily disable this macro to avoid conflict at definition. +* Place source MAC address in both `s_addr` and `S_un.S_addr` fields, +* so that access works either directly or through the macro. +*/ +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif +/** * Ethernet header: Contains the destination address, source address * and frame type. */ struct rte_ether_hdr {struct rte_ether_addr d_addr;/**< Destination address. */ -struct rte_ether_addr s_addr;/**< Source address. */ -uint16_t ether_type;/**< Frame type. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_addr; + } S_un;/**< Do not use directly; use s_addr instead.*/ + }; +uint16_t ether_type;/**< Frame type. */ }__rte_aligned (2 ); +#pragma pop_macro("s_addr") +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Signature · 1 line
2.29.3
PATCH v7 5/5 net: provide IP-related API on any OS
In reply to Dmitry KozlyukUsers of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constants, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.
Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX includes in components enabled on Windows. Move missing constants from Windows networking shim to OS shim header and include it where needed.
Remove Windows networking shim that is no longer needed.
--- drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +-- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 --- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ---------------- lib/librte_eal/windows/include/netinet/in.h | 38 -------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ------ lib/librte_eal/windows/include/rte_os_shim.h | 8 +++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------- lib/librte_ethdev/rte_ethdev.c | 12 +++---- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 7 ++++ lib/librte_net/rte_net.c | 1 + 21 files changed, 24 insertions(+), 141 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_type.h"
drivers/net/mlx5/mlx5.h +0 -1
@@ -10,7 +10,6 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> #include <sys/queue.h> #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +1 -3
@@ -3,12 +3,11 @@* Copyright 2016 Mellanox Technologies, Ltd */ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +#include <sys/queue.h> #include <rte_common.h> #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh, { }#endif /* HAVE_IBV_FLOW_DV_SUPPORT */ -
drivers/net/mlx5/mlx5_flow.h +1 -2
@@ -5,11 +5,10 @@#ifndef RTE_PMD_MLX5_FLOW_H_ #define RTE_PMD_MLX5_FLOW_H_ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> +#include <sys/queue.h> #include <rte_alarm.h> #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
@@ -8,7 +8,6 @@#include <string.h> #include <inttypes.h> #include <errno.h> -#include <netinet/in.h> #include <rte_ether.h> #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
@@ -8,12 +8,7 @@#include <stdint.h> #include <string.h> #include <stdlib.h> -#include <stdarg.h> #include <errno.h> -#include <netinet/in.h> -#ifdef RTE_EXEC_ENV_FREEBSD -#include <sys/socket.h> -#endif #include <cmdline_rdline.h> #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
@@ -6,11 +6,9 @@#include <stdio.h> #include <inttypes.h> -#include <stdarg.h> #include <errno.h> #include <ctype.h> #include <string.h> -#include <netinet/in.h> #include <cmdline_parse.h> #include <cmdline_parse_ipaddr.h>
lib/librte_cmdline/cmdline.c +0 -1
@@ -12,7 +12,6 @@#include <inttypes.h> #include <fcntl.h> #include <errno.h> -#include <netinet/in.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse.c +0 -2
@@ -11,8 +11,6 @@#include <inttypes.h> #include <ctype.h> -#include <netinet/in.h> -#include <rte_string_fns.h> #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
@@ -5,13 +5,7 @@*/ #include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> -#include <sys/types.h> #include <rte_string_fns.h> #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
@@ -6,14 +6,8 @@#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> #include <errno.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
@@ -8,7 +8,7 @@#define _PARSE_IPADDR_H_#include <cmdline_parse.h> -#include <netinet/in.h> +#include <rte_ip.h> #ifdef __cplusplusextern "C" {
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _ARPA_INET_H_ -#define _ARPA_INET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <netinet/in.h> -#include <sys/socket.h> - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -int -inet_pton (int af,const char *src,void *dst); - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -const char * -inet_ntop (int af,const void *src,char *dst,socklen_t size); - -#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IN_H_ -#define _IN_H_ - -#include <stdint.h> -#include <sys/socket.h> - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_SCTP 132 - -#define INET6_ADDRSTRLEN 46 - -struct in_addr { -uint32_t s_addr; -}; - -struct in6_addr { -uint8_t s6_addr[16 ]; -}; - -#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
@@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IP_H_ -#define _IP_H_ - -#define IPVERSION 4 - -#endif
lib/librte_eal/windows/include/rte_os_shim.h +8 -0
@@ -25,4 +25,12 @@#define close (fd) _close(fd)#define unlink (path) _unlink(path) +#define IPVERSION 4 + +#define IPPROTO_IPIP 4 +#define IPPROTO_GRE 47 +#ifdef RTE_TOOLCHAIN_GCC +#define IPPROTO_SCTP 132 +#endif +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <stddef.h> - -#define AF_INET 2 -#define AF_INET6 23 - -typedef size_t socklen_t ; - -#endif /* _SYS_SOCKET_H_ */
lib/librte_ethdev/rte_ethdev.c +4 -8
@@ -2,18 +2,14 @@* Copyright(c) 2010-2017 Intel Corporation */ -#include <sys/types.h> -#include <sys/queue.h> #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdint.h> -#include <inttypes.h> -#include <netinet/in.h> +#include <stdlib.h> +#include <string.h> +#include <sys/queue.h> #include <rte_byteorder.h> #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
@@ -6,7 +6,6 @@#define _RTE_ETHDEV_CORE_H_#include <pthread.h> -#include <sys/types.h> /** * @file
lib/librte_net/rte_ip.h +7 -0
@@ -16,9 +16,16 @@*/ #include <stdint.h> + +#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else +#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif #include <rte_byteorder.h> #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_shim.h> /* get l3 packet type from ip6 next protocol */ static uint32_t
Signature · 1 line
2.29.3
v8 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v8:
* Drop rte_thread_sleep API, use rte_delay_us_sleep (Morten Brørup).
v7:
* Rearrange patches, improve wording, fix typo.
* rte_os_internal.h -> rte_os_shim.h for possible later exposure
* Remove unnecessary blank lines.
*** BLURB HERE ***
Dmitry Kozlyuk (4):
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 -- examples/cmdline/parse_obj_list.c | 2 - lib/librte_cmdline/cmdline.c | 5 -- lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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/common/eal_private.h | 11 +++ 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.c | 30 +++++++ 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/arpa/inet.h | 30 ------- lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 --- lib/librte_eal/windows/include/rte_os.h | 92 +------------------- lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 12 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 44 files changed, 164 insertions(+), 253 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 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.3
PATCH v8 1/4 eal/windows: hide asprintf() shim
Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++ lib/librte_eal/windows/include/rte_os.h | 30 ------------------------- 3 files changed, 41 insertions(+), 30 deletions(-)
lib/librte_eal/common/eal_private.h +11 -0
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
lib/librte_eal/windows/include/rte_os.h +0 -30
@@ -10,7 +10,6 @@* which is not supported natively or named differently in Windows. */ -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {typedef long long ssize_t ;#ifndef RTE_TOOLCHAIN_GCC - -static inline int -asprintf (char **buffer,const char *format, ...) -{ -int size, ret; -va_list arg; - -va_start (arg, format); - size =vsnprintf (NULL ,0 , format, arg); -va_end (arg); -if (size <0 ) -return -1 ; - size++; - - *buffer = (char *)malloc (size); -if (*buffer ==NULL ) -return -1 ; - -va_start (arg, format); - ret =vsnprintf (*buffer, size, format, arg); -va_end (arg); -if (ret != size -1 ) { -free (*buffer); -return -1 ; - } -return ret; -} -static inline const char *eal_strerror (int code) {
@@ -111,7 +82,6 @@ eal_strerror(int code)#ifndef strerror#define strerror eal_strerror#endif -#endif /* RTE_TOOLCHAIN_GCC */ #ifdef __cplusplus
Signature · 1 line
2.29.3
PATCH v8 2/4 eal: make OS shims internal
In reply to Dmitry KozlyukDPDK 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 <rte_os.h> 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 <rte_os_shim.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>. Directly replace shims that were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s
--- 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
drivers/bus/pci/private.h +3 -1
@@ -7,8 +7,10 @@#include <stdbool.h> #include <stdio.h> -#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_os_shim.h> +#include <rte_pci.h> extern struct rte_pci_bus rte_pci_bus;
drivers/bus/vdev/vdev_private.h +2 -0
@@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include <rte_os_shim.h> + #ifdef __cplusplus extern "C" { #endif
drivers/common/mlx5/mlx5_common.h +1 -0
@@ -14,6 +14,7 @@#include <rte_kvargs.h> #include <rte_devargs.h> #include <rte_bitops.h> +#include <rte_os_shim.h> #include "mlx5_prm.h" #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -27,6 +27,7 @@#include <rte_tailq.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_prototype.h"
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
@@ -4,8 +4,6 @@#include <io.h> -#include <rte_os.h> -#include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
@@ -8,6 +8,7 @@#include <stdarg.h> #include <rte_common.h> +#include <rte_os_shim.h> #ifdef RTE_EXEC_ENV_WINDOWS #include <rte_windows.h> #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_config.c +0 -1
@@ -3,7 +3,6 @@*/ #include <string.h> -#include <rte_os.h> #include <rte_string_fns.h> #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 ;
lib/librte_eal/common/eal_common_timer.c +2 -2
@@ -47,9 +47,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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 ); }
lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -11,6 +11,7 @@#define EAL_INTERNAL_CFG_H #include <rte_eal.h> +#include <rte_os_shim.h> #include <rte_pci_dev_feature_defs.h> #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/linux/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
@@ -6,7 +6,6 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_memzone.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
@@ -9,7 +9,6 @@#include <rte_common.h> #include <rte_debug.h> #include <rte_lcore.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
@@ -3,7 +3,6 @@*/ #include <rte_errno.h> -#include <rte_os.h> #include "eal_internal_cfg.h" #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -58
76 lines not on this page · raw message
lib/librte_eal/windows/include/rte_os_shim.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @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_ */
lib/librte_ethdev/ethdev_private.h +2 -0
@@ -5,6 +5,8 @@#ifndef _ETH_PRIVATE_H_#define _ETH_PRIVATE_H_ +#include <rte_os_shim.h> +#include "rte_ethdev.h" #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
@@ -7,6 +7,7 @@#include <stdlib.h> #include <stdbool.h> +#include <rte_os_shim.h> #include <rte_string_fns.h> #include "rte_kvargs.h"
Signature · 1 line
2.29.3
PATCH v8 3/4 net: work around s_addr macro on Windows
In reply to Dmitry KozlyukWindows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with definition of s_addr field of struct rte_ether_hdr. Prieviously s_addr was undefined in <rte_ether.h>, which had been breaking access to s_addr field of struct in_addr, so some DPDK and Windows headers could not be included in one file.
Renaming of struct rte_ether_hdr is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro as defined in Windows headers.
--- lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
lib/librte_net/rte_ether.h +20 -6
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +/* Windows Sockets headers contain `#define s_addr S_un.S_addr`. +* Temporarily disable this macro to avoid conflict at definition. +* Place source MAC address in both `s_addr` and `S_un.S_addr` fields, +* so that access works either directly or through the macro. +*/ +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif +/** * Ethernet header: Contains the destination address, source address * and frame type. */ struct rte_ether_hdr {struct rte_ether_addr d_addr;/**< Destination address. */ -struct rte_ether_addr s_addr;/**< Source address. */ -uint16_t ether_type;/**< Frame type. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_addr; + } S_un;/**< Do not use directly; use s_addr instead.*/ + }; +uint16_t ether_type;/**< Frame type. */ }__rte_aligned (2 ); +#pragma pop_macro("s_addr") +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows
Quoted 9 lines · Dmitry Kozlyuk
Windows Sockets headers contain
#define s_addr S_un.S_addr, which conflicts with definition ofs_addrfield ofstruct rte_ether_hdr. Prieviouslys_addrwas undefined in <rte_ether.h>, which had been breaking access tos_addrfield ofstruct in_addr, so some DPDK and Windows headers could not be included in one file.Renaming of
struct rte_ether_hdris planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Quoted 7 lines
Temporarily disable
s_addrmacro aroundstruct rte_ether_hdrdefinition to avoid conflict. Place source MAC address in boths_addrandS_un.S_addrfields, so that access works either directly or through the macro as defined in Windows headers.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Ranjit Menon <[email protected]>
PATCH v8 4/4 net: provide IP-related API on any OS
In reply to Dmitry KozlyukUsers of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constants, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.
Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX includes in components enabled on Windows. Move missing constants from Windows networking shim to OS shim header and include it where needed.
Remove Windows networking shim that is no longer needed.
--- drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +-- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 --- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ---------------- lib/librte_eal/windows/include/netinet/in.h | 38 -------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ------ lib/librte_eal/windows/include/rte_os_shim.h | 8 +++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------- lib/librte_ethdev/rte_ethdev.c | 12 +++---- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 7 ++++ lib/librte_net/rte_net.c | 1 + 21 files changed, 24 insertions(+), 141 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_type.h"
drivers/net/mlx5/mlx5.h +0 -1
@@ -10,7 +10,6 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> #include <sys/queue.h> #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +1 -3
@@ -3,12 +3,11 @@* Copyright 2016 Mellanox Technologies, Ltd */ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +#include <sys/queue.h> #include <rte_common.h> #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh, { }#endif /* HAVE_IBV_FLOW_DV_SUPPORT */ -
drivers/net/mlx5/mlx5_flow.h +1 -2
@@ -5,11 +5,10 @@#ifndef RTE_PMD_MLX5_FLOW_H_ #define RTE_PMD_MLX5_FLOW_H_ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> +#include <sys/queue.h> #include <rte_alarm.h> #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
@@ -8,7 +8,6 @@#include <string.h> #include <inttypes.h> #include <errno.h> -#include <netinet/in.h> #include <rte_ether.h> #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
@@ -8,12 +8,7 @@#include <stdint.h> #include <string.h> #include <stdlib.h> -#include <stdarg.h> #include <errno.h> -#include <netinet/in.h> -#ifdef RTE_EXEC_ENV_FREEBSD -#include <sys/socket.h> -#endif #include <cmdline_rdline.h> #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
@@ -6,11 +6,9 @@#include <stdio.h> #include <inttypes.h> -#include <stdarg.h> #include <errno.h> #include <ctype.h> #include <string.h> -#include <netinet/in.h> #include <cmdline_parse.h> #include <cmdline_parse_ipaddr.h>
lib/librte_cmdline/cmdline.c +0 -1
@@ -12,7 +12,6 @@#include <inttypes.h> #include <fcntl.h> #include <errno.h> -#include <netinet/in.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse.c +0 -2
@@ -11,8 +11,6 @@#include <inttypes.h> #include <ctype.h> -#include <netinet/in.h> -#include <rte_string_fns.h> #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
@@ -5,13 +5,7 @@*/ #include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> -#include <sys/types.h> #include <rte_string_fns.h> #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
@@ -6,14 +6,8 @@#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> #include <errno.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
@@ -8,7 +8,7 @@#define _PARSE_IPADDR_H_#include <cmdline_parse.h> -#include <netinet/in.h> +#include <rte_ip.h> #ifdef __cplusplusextern "C" {
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _ARPA_INET_H_ -#define _ARPA_INET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <netinet/in.h> -#include <sys/socket.h> - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -int -inet_pton (int af,const char *src,void *dst); - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -const char * -inet_ntop (int af,const void *src,char *dst,socklen_t size); - -#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IN_H_ -#define _IN_H_ - -#include <stdint.h> -#include <sys/socket.h> - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_SCTP 132 - -#define INET6_ADDRSTRLEN 46 - -struct in_addr { -uint32_t s_addr; -}; - -struct in6_addr { -uint8_t s6_addr[16 ]; -}; - -#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
@@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IP_H_ -#define _IP_H_ - -#define IPVERSION 4 - -#endif
lib/librte_eal/windows/include/rte_os_shim.h +8 -0
@@ -25,4 +25,12 @@#define close (fd) _close(fd)#define unlink (path) _unlink(path) +#define IPVERSION 4 + +#define IPPROTO_IPIP 4 +#define IPPROTO_GRE 47 +#ifdef RTE_TOOLCHAIN_GCC +#define IPPROTO_SCTP 132 +#endif +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <stddef.h> - -#define AF_INET 2 -#define AF_INET6 23 - -typedef size_t socklen_t ; - -#endif /* _SYS_SOCKET_H_ */
lib/librte_ethdev/rte_ethdev.c +4 -8
@@ -2,18 +2,14 @@* Copyright(c) 2010-2017 Intel Corporation */ -#include <sys/types.h> -#include <sys/queue.h> #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdint.h> -#include <inttypes.h> -#include <netinet/in.h> +#include <stdlib.h> +#include <string.h> +#include <sys/queue.h> #include <rte_byteorder.h> #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
@@ -6,7 +6,6 @@#define _RTE_ETHDEV_CORE_H_#include <pthread.h> -#include <sys/types.h> /** * @file
lib/librte_net/rte_ip.h +7 -0
@@ -16,9 +16,16 @@*/ #include <stdint.h> + +#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else +#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif #include <rte_byteorder.h> #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_shim.h> /* get l3 packet type from ip6 next protocol */ static uint32_t
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
Hi Dmitry,
Quoted 31 lines · Dmitry Kozlyuk
Users of <
rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constants, but still had to include POSIX headers forinet_pton()and other standard IP-related facilities.Extend <
rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX includes in components enabled on Windows. Move missing constants from Windows networking shim to OS shim header and include it where needed.Remove Windows networking shim that is no longer needed.
Signed-off-by Dmitry Kozlyuk <[email protected]>--- drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +-- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 --- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ---------------- lib/librte_eal/windows/include/netinet/in.h | 38 -------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ------ lib/librte_eal/windows/include/rte_os_shim.h | 8 +++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------- lib/librte_ethdev/rte_ethdev.c | 12 +++----
Quoted 8 lines
lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 7 ++++ lib/librte_net/rte_net.c | 1 + 21 files changed, 24 insertions(+), 141 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
I see it has already been discussed for posix functions like close() or strdup(), so I won't reopen the door too long ;)
Since DPDK is a network-oriented project, it provides network defines or structure, prefixed with rte_. This API is on some aspects more complete than the one provided in libc (for instance, more protocol headers are available) . So, to me, it would make sense to define RTE_IPPROTO_* and replace usages of IPPROTO_*, and avoid inclusions of network libc headers in DPDK code.
This can be done later, if there is a consensus.
drivers/net/i40e/i40e_fdir.c line 26
Quoted 10 lines
drivers/net/i40e/i40e_fdir.c +1
-0@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h>
If I understand the logic, rte_ip.h provides OS-specific IP-related stuff (like IPPROTO_*), and rte_os_shim.h provides the POSIX definitions that are missing after including rte_ip.h.
Would it make sense to include rte_os_shim.h from rte_ip.h, so that including rte_ip.h is always sufficient? Or is it because we want to avoid implicit inclusion of rte_os_shim.h?
Thanks,
Olivier
Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
2021-04-08 13:45 (UTC+0200), Olivier Matz:
[...]
Quoted 15 lines
drivers/net/i40e/i40e_fdir.c line 26
Quoted 10 lines
drivers/net/i40e/i40e_fdir.c +1
-0@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> If I understand the logic,
rte_ip.hprovides OS-specific IP-related stuff (like IPPROTO_*), andrte_os_shim.hprovides the POSIX definitions that are missing after includingrte_ip.h.
Quoted 3 lines
Would it make sense to include
rte_os_shim.hfromrte_ip.h, so that includingrte_ip.his always sufficient? Or is it because we want to avoid implicit inclusion ofrte_os_shim.h?
Yes, currently rte_os_shim.h is not exposed at all. It it ever will, this reason still applies.
Olivier Matz
Acked-byRe: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
Quoted 17 lines · Dmitry Kozlyuk
2021-04-08 13:45 (UTC+0200), Olivier Matz:
[...]Quoted 15 lines
drivers/net/i40e/i40e_fdir.c line 26
Quoted 10 lines
drivers/net/i40e/i40e_fdir.c +1
-0@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> If I understand the logic,
rte_ip.hprovides OS-specific IP-related stuff (like IPPROTO_*), andrte_os_shim.hprovides the POSIX definitions that are missing after includingrte_ip.h.
Quoted 6 lines
Quoted 3 lines
Would it make sense to include
rte_os_shim.hfromrte_ip.h, so that includingrte_ip.his always sufficient? Or is it because we want to avoid implicit inclusion ofrte_os_shim.h?Yes, currently
rte_os_shim.his not exposed at all. It it ever will, this reason still applies.
Ok, thank you for the clarification.
Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
In reply to Olivier Matz08/04/2021 13:45, Olivier Matz:
Quoted 11 lines
I see it has already been discussed for posix functions like
close()orstrdup(), so I won't reopen the door too long ;)Since DPDK is a network-oriented project, it provides network defines or structure, prefixed with
rte_. This API is on some aspects more complete than the one provided in libc (for instance, more protocol headers are available) . So, to me, it would make sense to define RTE_IPPROTO_* and replace usages of IPPROTO_*, and avoid inclusions of network libc headers in DPDK code.This can be done later, if there is a consensus.
That's an interesting question.
What would be the benefit of avoiding network libc includes?
v9 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v9:
* Fix missing <rte_os_shim.h> include in rte_common_log.c. (This will happen again. Going to add a checkpatch test after this series is merged.)
v8:
* Drop rte_thread_sleep API, use rte_delay_us_sleep (Morten Brørup).
Dmitry Kozlyuk (4):
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 -- examples/cmdline/parse_obj_list.c | 2 - lib/librte_cmdline/cmdline.c | 5 -- lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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_log.c | 1 + 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/common/eal_private.h | 11 +++ 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.c | 30 +++++++ 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/arpa/inet.h | 30 ------- lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 --- lib/librte_eal/windows/include/rte_os.h | 92 +------------------- lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 12 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 45 files changed, 165 insertions(+), 253 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 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.3
PATCH v9 1/4 eal/windows: hide asprintf() shim
Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++ lib/librte_eal/windows/include/rte_os.h | 30 ------------------------- 3 files changed, 41 insertions(+), 30 deletions(-)
lib/librte_eal/common/eal_private.h +11 -0
@@ -716,4 +716,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -416,6 +418,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
lib/librte_eal/windows/include/rte_os.h +0 -30
@@ -10,7 +10,6 @@* which is not supported natively or named differently in Windows. */ -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {typedef long long ssize_t ;#ifndef RTE_TOOLCHAIN_GCC - -static inline int -asprintf (char **buffer,const char *format, ...) -{ -int size, ret; -va_list arg; - -va_start (arg, format); - size =vsnprintf (NULL ,0 , format, arg); -va_end (arg); -if (size <0 ) -return -1 ; - size++; - - *buffer = (char *)malloc (size); -if (*buffer ==NULL ) -return -1 ; - -va_start (arg, format); - ret =vsnprintf (*buffer, size, format, arg); -va_end (arg); -if (ret != size -1 ) { -free (*buffer); -return -1 ; - } -return ret; -} -static inline const char *eal_strerror (int code) {
@@ -111,7 +82,6 @@ eal_strerror(int code)#ifndef strerror#define strerror eal_strerror#endif -#endif /* RTE_TOOLCHAIN_GCC */ #ifdef __cplusplus
Signature · 1 line
2.29.3
PATCH v9 2/4 eal: make OS shims internal
In reply to Dmitry KozlyukDPDK 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 <rte_os.h> 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 <rte_os_shim.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>. Directly replace shims that were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s
--- 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_log.c | 1 + 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 + 23 files changed, 80 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
drivers/bus/pci/private.h +3 -1
@@ -7,8 +7,10 @@#include <stdbool.h> #include <stdio.h> -#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_os_shim.h> +#include <rte_pci.h> extern struct rte_pci_bus rte_pci_bus;
drivers/bus/vdev/vdev_private.h +2 -0
@@ -5,6 +5,8 @@ #ifndef _VDEV_PRIVATE_H_ #define _VDEV_PRIVATE_H_ +#include <rte_os_shim.h> + #ifdef __cplusplus extern "C" { #endif
drivers/common/mlx5/mlx5_common.h +1 -0
@@ -14,6 +14,7 @@#include <rte_kvargs.h> #include <rte_devargs.h> #include <rte_bitops.h> +#include <rte_os_shim.h> #include "mlx5_prm.h" #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -27,6 +27,7 @@#include <rte_tailq.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_prototype.h"
lib/librte_cmdline/cmdline.c +0 -4
@@ -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)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
@@ -4,8 +4,6 @@#include <io.h> -#include <rte_os.h> -#include "cmdline_private.h" /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
@@ -8,6 +8,7 @@#include <stdarg.h> #include <rte_common.h> +#include <rte_os_shim.h> #ifdef RTE_EXEC_ENV_WINDOWS #include <rte_windows.h> #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
@@ -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) {
lib/librte_eal/common/eal_common_config.c +0 -1
@@ -3,7 +3,6 @@*/ #include <string.h> -#include <rte_os.h> #include <rte_string_fns.h> #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
@@ -15,6 +15,10 @@#include <rte_errno.h> #include <rte_string_fns.h> +#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 *
lib/librte_eal/common/eal_common_log.c +1 -0
@@ -13,6 +13,7 @@#include <rte_eal.h> #include <rte_log.h> +#include <rte_os_shim.h> #include <rte_per_lcore.h> #include "eal_log.h"
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -1959,7 +1959,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 ;
lib/librte_eal/common/eal_common_timer.c +2 -2
@@ -47,9 +47,9 @@ estimate_tsc_freq(void)#define CYC_PER_10MHZ 1E7RTE_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 ); }
lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -11,6 +11,7 @@#define EAL_INTERNAL_CFG_H #include <rte_eal.h> +#include <rte_os_shim.h> #include <rte_pci_dev_feature_defs.h> #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/linux/include/rte_os_shim.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @file +* @internal +* Provides semi-standard OS facilities by convenient names. +*/ + +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
@@ -6,7 +6,6 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_memzone.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
@@ -9,7 +9,6 @@#include <rte_common.h> #include <rte_debug.h> #include <rte_lcore.h> -#include <rte_os.h> #include "eal_private.h" #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
@@ -3,7 +3,6 @@*/ #include <rte_errno.h> -#include <rte_os.h> #include "eal_internal_cfg.h" #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -58
76 lines not on this page · raw message
lib/librte_eal/windows/include/rte_os_shim.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _RTE_OS_SHIM_ +#define _RTE_OS_SHIM_ + +#include <rte_os.h> + +/** +* @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_ */
lib/librte_ethdev/ethdev_private.h +2 -0
@@ -5,6 +5,8 @@#ifndef _ETH_PRIVATE_H_#define _ETH_PRIVATE_H_ +#include <rte_os_shim.h> +#include "rte_ethdev.h" #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
@@ -7,6 +7,7 @@#include <stdlib.h> #include <stdbool.h> +#include <rte_os_shim.h> #include <rte_string_fns.h> #include "rte_kvargs.h"
Signature · 1 line
2.29.3
Re: [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal
11/04/2021 00:47, Dmitry Kozlyuk:
Quoted 14 lines
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 <
rte_os.h> 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 <
rte_os_shim.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>. Directly replace shims that were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep ->rte_delay_us_sleep
*strerror_r->strerror_s
Quoted 1 line
Signed-off-by Dmitry Kozlyuk <[email protected]>
PATCH v9 3/4 net: work around s_addr macro on Windows
In reply to Dmitry KozlyukWindows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with definition of s_addr field of struct rte_ether_hdr. Prieviously s_addr was undefined in <rte_ether.h>, which had been breaking access to s_addr field of struct in_addr, so some DPDK and Windows headers could not be included in one file.
Renaming of struct rte_ether_hdr is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html
Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro as defined in Windows headers.
--- lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
lib/librte_net/rte_ether.h +20 -6
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +/* Windows Sockets headers contain `#define s_addr S_un.S_addr`. +* Temporarily disable this macro to avoid conflict at definition. +* Place source MAC address in both `s_addr` and `S_un.S_addr` fields, +* so that access works either directly or through the macro. +*/ +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif +/** * Ethernet header: Contains the destination address, source address * and frame type. */ struct rte_ether_hdr {struct rte_ether_addr d_addr;/**< Destination address. */ -struct rte_ether_addr s_addr;/**< Source address. */ -uint16_t ether_type;/**< Frame type. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_addr; + } S_un;/**< Do not use directly; use s_addr instead.*/ + }; +uint16_t ether_type;/**< Frame type. */ }__rte_aligned (2 ); +#pragma pop_macro("s_addr") +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Signature · 1 line
2.29.3
PATCH v9 4/4 net: provide IP-related API on any OS
In reply to Dmitry KozlyukUsers of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constants, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.
Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX includes in components enabled on Windows. Move missing constants from Windows networking shim to OS shim header and include it where needed.
Remove Windows networking shim that is no longer needed.
--- drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +-- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 --- examples/cmdline/parse_obj_list.c | 2 -- lib/librte_cmdline/cmdline.c | 1 - lib/librte_cmdline/cmdline_parse.c | 2 -- lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 ---- lib/librte_cmdline/cmdline_parse_ipaddr.h | 2 +- lib/librte_eal/windows/include/arpa/inet.h | 30 ---------------- lib/librte_eal/windows/include/netinet/in.h | 38 -------------------- lib/librte_eal/windows/include/netinet/ip.h | 10 ------ lib/librte_eal/windows/include/rte_os_shim.h | 8 +++++ lib/librte_eal/windows/include/sys/socket.h | 24 ------------- lib/librte_ethdev/rte_ethdev.c | 12 +++---- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_net/rte_ip.h | 7 ++++ lib/librte_net/rte_net.c | 1 + 21 files changed, 24 insertions(+), 141 deletions(-) delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
@@ -22,6 +22,7 @@#include <rte_sctp.h> #include <rte_hash_crc.h> #include <rte_bitmap.h> +#include <rte_os_shim.h> #include "i40e_logs.h" #include "base/i40e_type.h"
drivers/net/mlx5/mlx5.h +0 -1
@@ -10,7 +10,6 @@#include <stdbool.h> #include <stdint.h> #include <limits.h> -#include <netinet/in.h> #include <sys/queue.h> #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +1 -3
@@ -3,12 +3,11 @@* Copyright 2016 Mellanox Technologies, Ltd */ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +#include <sys/queue.h> #include <rte_common.h> #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh, { }#endif /* HAVE_IBV_FLOW_DV_SUPPORT */ -
drivers/net/mlx5/mlx5_flow.h +1 -2
@@ -5,11 +5,10 @@#ifndef RTE_PMD_MLX5_FLOW_H_ #define RTE_PMD_MLX5_FLOW_H_ -#include <netinet/in.h> -#include <sys/queue.h> #include <stdalign.h> #include <stdint.h> #include <string.h> +#include <sys/queue.h> #include <rte_alarm.h> #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
@@ -8,7 +8,6 @@#include <string.h> #include <inttypes.h> #include <errno.h> -#include <netinet/in.h> #include <rte_ether.h> #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
@@ -8,12 +8,7 @@#include <stdint.h> #include <string.h> #include <stdlib.h> -#include <stdarg.h> #include <errno.h> -#include <netinet/in.h> -#ifdef RTE_EXEC_ENV_FREEBSD -#include <sys/socket.h> -#endif #include <cmdline_rdline.h> #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
@@ -6,11 +6,9 @@#include <stdio.h> #include <inttypes.h> -#include <stdarg.h> #include <errno.h> #include <ctype.h> #include <string.h> -#include <netinet/in.h> #include <cmdline_parse.h> #include <cmdline_parse_ipaddr.h>
lib/librte_cmdline/cmdline.c +0 -1
@@ -12,7 +12,6 @@#include <inttypes.h> #include <fcntl.h> #include <errno.h> -#include <netinet/in.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse.c +0 -2
@@ -11,8 +11,6 @@#include <inttypes.h> #include <ctype.h> -#include <netinet/in.h> -#include <rte_string_fns.h> #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
@@ -5,13 +5,7 @@*/ #include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> -#include <sys/types.h> #include <rte_string_fns.h> #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
@@ -6,14 +6,8 @@#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> -#include <inttypes.h> -#include <ctype.h> #include <string.h> #include <errno.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <rte_string_fns.h>
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
@@ -8,7 +8,7 @@#define _PARSE_IPADDR_H_#include <cmdline_parse.h> -#include <netinet/in.h> +#include <rte_ip.h> #ifdef __cplusplusextern "C" {
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _ARPA_INET_H_ -#define _ARPA_INET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <netinet/in.h> -#include <sys/socket.h> - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -int -inet_pton (int af,const char *src,void *dst); - -/* defined in ws2_32.dll */ -__attribute__((stdcall)) -const char * -inet_ntop (int af,const void *src,char *dst,socklen_t size); - -#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IN_H_ -#define _IN_H_ - -#include <stdint.h> -#include <sys/socket.h> - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_SCTP 132 - -#define INET6_ADDRSTRLEN 46 - -struct in_addr { -uint32_t s_addr; -}; - -struct in6_addr { -uint8_t s6_addr[16 ]; -}; - -#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
@@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2020 Mellanox Technologies, Ltd -*/ - -#ifndef _IP_H_ -#define _IP_H_ - -#define IPVERSION 4 - -#endif
lib/librte_eal/windows/include/rte_os_shim.h +8 -0
@@ -25,4 +25,12 @@#define close (fd) _close(fd)#define unlink (path) _unlink(path) +#define IPVERSION 4 + +#define IPPROTO_IPIP 4 +#define IPPROTO_GRE 47 +#ifdef RTE_TOOLCHAIN_GCC +#define IPPROTO_SCTP 132 +#endif +#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright (c) 2020 Dmitry Kozlyuk -*/ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/** -* @file -* -* Compatibility header -* -* Although symbols declared here are present on Windows, -* including <winsock2.h> would expose too much macros breaking common code. -*/ - -#include <stddef.h> - -#define AF_INET 2 -#define AF_INET6 23 - -typedef size_t socklen_t ; - -#endif /* _SYS_SOCKET_H_ */
lib/librte_ethdev/rte_ethdev.c +4 -8
@@ -2,18 +2,14 @@* Copyright(c) 2010-2017 Intel Corporation */ -#include <sys/types.h> -#include <sys/queue.h> #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdint.h> -#include <inttypes.h> -#include <netinet/in.h> +#include <stdlib.h> +#include <string.h> +#include <sys/queue.h> #include <rte_byteorder.h> #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
@@ -6,7 +6,6 @@#define _RTE_ETHDEV_CORE_H_#include <pthread.h> -#include <sys/types.h> /** * @file
lib/librte_net/rte_ip.h +7 -0
@@ -16,9 +16,16 @@*/ #include <stdint.h> + +#ifdef RTE_EXEC_ENV_WINDOWS +#include <ws2tcpip.h> +#else +#include <sys/socket.h> #include <sys/types.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ip.h> +#endif #include <rte_byteorder.h> #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
@@ -15,6 +15,7 @@#include <rte_gre.h> #include <rte_mpls.h> #include <rte_net.h> +#include <rte_os_shim.h> /* get l3 packet type from ip6 next protocol */ static uint32_t
Signature · 1 line
2.29.3
Hi Dmitry,
Quoted 14 lines · Dmitry Kozlyuk
On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.v9:
* Fix missing <rte_os_shim.h> include inrte_common_log.c. (This will happen again. Going to add a checkpatch test after this series is merged.)
v8:
* Droprte_thread_sleepAPI, userte_delay_us_sleep(Morten Brørup).
Quoted 7 lines
Dmitry Kozlyuk (4):
eal/windows: hideasprintf()shim
eal: make OS shims internal
net: work arounds_addrmacro on Windows
net: provide IP-related API on any OS<Snip>
The change to remove the networking shim breaks l2fwd compilation on Windows, since l2fwd/main.c includes netinet/in.h explicitly.
How do you propose we fix this, only for Windows?
ranjit m.
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]
Quoted 4 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 4 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]
Quoted 8 lines
Quoted 4 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Quoted 8 lines · Thomas Monjalon
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 7 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]Quoted 3 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Thanks, Thomas. For now, this is only required in l2fwd.
Dmitry, can you please include this in your patch 4/4?
thanks,
ranjit m.
Quoted 1 line
14/04/2021 23:34, Ranjit Menon:
Quoted 9 lines · Thomas Monjalon
Quoted 8 lines
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 7 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]Quoted 3 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Thanks, Thomas. For now, this is only required in l2fwd.
Only l2fwd is supported on Windows?
Quoted 1 line
Dmitry, can you please include this in your patch 4/4?
Ranjit, if you tell me what exactly is needed, I can do it and merge the series quickly.
Quoted 17 lines · Thomas Monjalon
14/04/2021 23:34, Ranjit Menon:
Quoted 16 lines · Thomas Monjalon
Quoted 15 lines
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 11 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]Quoted 4 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Quoted 6 lines
Quoted 1 line
Thanks, Thomas. For now, this is only required in l2fwd.
Only l2fwd is supported on Windows?
Quoted 1 line
Dmitry, can you please include this in your patch 4/4?
Ranjit, if you tell me what exactly is needed, I can do it and merge the series quickly.
Sure, Thomas. In l2wfd/main.c, all we need to do is remove the #include <netinet/in.h> line.
This include file will not exist on Windows anymore, and Dmitry determined that this include is not required in l2fwd on all platforms.
ranjit m.
Quoted 1 line
2021-04-14 14:47 (UTC-0700), Ranjit Menon:
Quoted 18 lines · Thomas Monjalon
Quoted 17 lines
14/04/2021 23:34, Ranjit Menon:
Quoted 16 lines · Thomas Monjalon
Quoted 15 lines
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 11 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]Quoted 4 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Thanks, Thomas. For now, this is only required in l2fwd.
Only l2fwd is supported on Windows?
Quoted 1 line
Dmitry, can you please include this in your patch 4/4?
Ranjit, if you tell me what exactly is needed, I can do it and merge the series quickly.
I've just sent v10 with all required fixes.
Quoted 5 lines
Sure, Thomas. In
l2wfd/main.c, all we need to do is remove the #include <netinet/in.h> line.This include file will not exist on Windows anymore, and Dmitry determined that this include is not required in l2fwd on all platforms.
For the reference, complete list of examples that can build for Windows:
helloworld
cmdline
flow_filtering
ipv4_multicast
l2fwd
link_status_interrupt
qos_meter
rxtx_callbacks (-Wformat with clang)
service_cores
skeleton
15/04/2021 00:08, Dmitry Kozlyuk:
Quoted 19 lines
2021-04-14 14:47 (UTC-0700), Ranjit Menon:
Quoted 18 lines · Thomas Monjalon
Quoted 17 lines
14/04/2021 23:34, Ranjit Menon:
Quoted 16 lines · Thomas Monjalon
Quoted 15 lines
13/04/2021 09:00, Dmitry Kozlyuk:
Quoted 11 lines
Hi Ranjit,
2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]Quoted 4 lines
The change to remove the networking shim breaks l2fwd compilation on Windows, since
l2fwd/main.cincludesnetinet/in.hexplicitly.How do you propose we fix this, only for Windows?
This include is redundant for this file on all platforms, it can be removed. Since -Dexamples=all doesn't work on Windows because of missing dependencies, I wonder which of them need fixing.
Let's fix the examples which are supported on Windows. Other examples may require more updates anyway.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Thanks, Thomas. For now, this is only required in l2fwd.
Only l2fwd is supported on Windows?
Quoted 1 line
Dmitry, can you please include this in your patch 4/4?
Ranjit, if you tell me what exactly is needed, I can do it and merge the series quickly.
I've just sent v10 with all required fixes.
Thank you
Some acks were removed from this v10, I am re-adding them.
Quoted 8 lines
Quoted 5 lines
Sure, Thomas. In
l2wfd/main.c, all we need to do is remove the #include <netinet/in.h> line.This include file will not exist on Windows anymore, and Dmitry determined that this include is not required in l2fwd on all platforms.
For the reference, complete list of examples that can build for Windows:
Quoted 10 lines
helloworld
cmdline
flow_filtering
ipv4_multicast
l2fwd
link_status_interrupt
qos_meter
rxtx_callbacks(-Wformat with clang)
service_cores
skeleton
devtools/test-meson-builds.sh should be updated to compile these examples with MinGW.
v10 cover eal/windows: do not expose POSIX symbols
In reply to Dmitry KozlyukOn Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.
v10:
* Fix examples that build on Windows.
v9:
* Fix missing <rte_os_shim.h> include in rte_common_log.c. (This will happen again. Going to add a checkpatch test after this series is merged.)
Dmitry Kozlyuk (4):
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS
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 + drivers/net/i40e/i40e_fdir.c | 1 + drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_mac.c | 1 - examples/cmdline/commands.c | 5 -- examples/cmdline/parse_obj_list.c | 2 - examples/flow_filtering/main.c | 1 - examples/l2fwd/main.c | 1 - examples/link_status_interrupt/main.c | 1 - examples/service_cores/main.c | 4 +- lib/librte_cmdline/cmdline.c | 5 -- lib/librte_cmdline/cmdline_os_windows.c | 2 - lib/librte_cmdline/cmdline_parse.c | 2 - lib/librte_cmdline/cmdline_parse_etheraddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.c | 6 -- lib/librte_cmdline/cmdline_parse_ipaddr.h | 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_log.c | 1 + 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/common/eal_private.h | 11 +++ 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.c | 30 +++++++ 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/arpa/inet.h | 30 ------- lib/librte_eal/windows/include/netinet/in.h | 38 -------- lib/librte_eal/windows/include/netinet/ip.h | 10 --- lib/librte_eal/windows/include/rte_os.h | 92 +------------------- lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++ lib/librte_eal/windows/include/sys/socket.h | 24 ----- lib/librte_ethdev/ethdev_private.h | 2 + lib/librte_ethdev/rte_ethdev.c | 12 +-- lib/librte_ethdev/rte_ethdev_core.h | 1 - lib/librte_kvargs/rte_kvargs.c | 1 + lib/librte_net/rte_ether.h | 26 ++++-- lib/librte_net/rte_ip.h | 7 ++ lib/librte_net/rte_net.c | 1 + 49 files changed, 167 insertions(+), 258 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 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
Signature · 1 line
2.29.3
PATCH v10 1/4 eal/windows: hide asprintf() shim
Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory.
--- lib/librte_eal/common/eal_private.h | 11 +++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++ lib/librte_eal/windows/include/rte_os.h | 30 ------------------------- 3 files changed, 41 insertions(+), 30 deletions(-)
lib/librte_eal/common/eal_private.h +11 -0
@@ -716,4 +716,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);*/ void __rte_thread_uninit (void ); +/** +* asprintf(3) replacement for Windows. +*/ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf (char **buffer,const char *format, ...); + +#define asprintf (buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/windows/eal.c +30 -0
@@ -2,6 +2,8 @@* Copyright(c) 2019 Intel Corporation */ +#include <stdarg.h> +#include <fcntl.h> #include <io.h> #include <share.h>
@@ -416,6 +418,34 @@ rte_eal_init(int argc, char **argv)return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf (char **buffer,const char *format, ...) +{ +int size, ret; +va_list arg; + +va_start (arg, format); + size =vsnprintf (NULL ,0 , format, arg); +va_end (arg); +if (size <0 ) +return -1 ; + size++; + + *buffer =malloc (size); +if (*buffer ==NULL ) +return -1 ; + +va_start (arg, format); + ret =vsnprintf (*buffer, size, format, arg); +va_end (arg); +if (ret != size -1 ) { +free (*buffer); +return -1 ; + } +return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr,
lib/librte_eal/windows/include/rte_os.h +0 -30
@@ -10,7 +10,6 @@* which is not supported natively or named differently in Windows. */ -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {typedef long long ssize_t ;#ifndef RTE_TOOLCHAIN_GCC - -static inline int -asprintf (char **buffer,const char *format, ...) -{ -int size, ret; -va_list arg; - -va_start (arg, format); - size =vsnprintf (NULL ,0 , format, arg); -va_end (arg); -if (size <0 ) -return -1 ; - size++; - - *buffer = (char *)malloc (size); -if (*buffer ==NULL ) -return -1 ; - -va_start (arg, format); - ret =vsnprintf (*buffer, size, format, arg); -va_end (arg); -if (ret != size -1 ) { -free (*buffer); -return -1 ; - } -return ret; -} -static inline const char *eal_strerror (int code) {
@@ -111,7 +82,6 @@ eal_strerror(int code)#ifndef strerror#define strerror eal_strerror#endif -#endif /* RTE_TOOLCHAIN_GCC */ #ifdef __cplusplus
Signature · 1 line
2.29.3