From patchwork Sat Mar 6 00:04:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 88592 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D5EFFA0547; Sat, 6 Mar 2021 01:05:19 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D7FF822A2F2; Sat, 6 Mar 2021 01:05:12 +0100 (CET) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mails.dpdk.org (Postfix) with ESMTP id DEC4122A301 for ; Sat, 6 Mar 2021 01:05:11 +0100 (CET) Received: by mail-lj1-f180.google.com with SMTP id a17so5209019ljq.2 for ; Fri, 05 Mar 2021 16:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AS96G1YFih6NNwXAlMJI/tRCj/qFEuYIDqE/fPn088I=; b=JPaAFNa7HV3/6fCjTuiOQlZMlRIofpm95AO7o62qeeJWux5obpGU2DZF+MtVkXEoYO gT3WK4hK+JVMz2zgCXqEjh0wUtsgXYcSQuwgy+bgeLSxMn26U6ufdWfsXSsPpER9j0Z4 Mwf74j5ab9zGzC0BtSd859puIIAOB37REFzpLKM+Ab3aCKPpOLdgNm1T1qGUfANpR3Kl x+NDfD0sYyo1VTcW/50obyiF1whaJqh3WWh9ZisoSn1rsPcbdS0Xa+Plzqg+yqb6uqNz JeIuAY8kkkUEQVJOoy0yv2bP6RX35peWpwvZT7hDFdGmWbAdSTV1Lf8kq4TjdfTjezyp Jihg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AS96G1YFih6NNwXAlMJI/tRCj/qFEuYIDqE/fPn088I=; b=FPlsRrK/NHxZFfR+p9bajHkF/oWHypzArSj6qRgfWlox2j+uP1DeE1aIAAf7+7uE4o PsbD1Itz3HruzTE6oI1zS8QPx2x4VUks5KnpkrL/j3xedptRlHbdpc5xohMnOF/IuKFo UZzQFVAagtD4RFu/VuDBFfdugAkZXxrWbPbhuRRPciPMBcfxDpTiE5TJJNw4JvU0qfOD 1qQDXMuy5/EbHrOfQaUsXk1a/uLN3mWosHFhhnkKYwZt6pI8hSkop0Cbj0LFOtX8AWHX n/j3Eszx1ESJGZrhjnwkF3cEKGctTFi6ZgOefZVu+/4xRPx9RNCnqBI3moYbaae/xOVH WS1Q== X-Gm-Message-State: AOAM5313sAN1ThBWlBK1FfmG805iSHV2zf7odrZyVDGEV2NSUJyc7LOv Vl9SVmsz1gNMy6+AkTMhs3a1Q0f2rZJn2A== X-Google-Smtp-Source: ABdhPJy1Wwf35DSsEUNLhqtaIGhwCXyN4Yboyl4pTeg9QCbNrHGEBqK6v4DsIfw/7bHEmC4DiQgJAg== X-Received: by 2002:a2e:3907:: with SMTP id g7mr6932021lja.159.1614989111156; Fri, 05 Mar 2021 16:05:11 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id s22sm494645ljd.28.2021.03.05.16.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 16:05:10 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Nick Connolly , Khoa To , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Date: Sat, 6 Mar 2021 03:04:57 +0300 Message-Id: <20210306000500.8698-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> References: <20210221142819.6769-1-dmitry.kozliuk@gmail.com> <20210306000500.8698-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 1/4] eal: add sleep API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" POSIX sleep(3) is missing from Windows. Add generic rte_thread_sleep() to suspend current OS thread. Signed-off-by: Dmitry Kozlyuk Acked-by: Khoa To --- 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(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 71e0bd035..0e89a4f7d 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_memcfg.h" @@ -47,9 +48,9 @@ estimate_tsc_freq(void) #define CYC_PER_10MHZ 1E7 RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly" " - clock timings may be less accurate.\n"); - /* assume that the sleep(1) will sleep for 1 second */ + /* assume that the rte_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); } diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h index e640ea185..f0c12dd79 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -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 diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 474cf123f..494240b94 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c index 86ffeebc9..91babfe88 100644 --- a/lib/librte_eal/unix/rte_thread.c +++ b/lib/librte_eal/unix/rte_thread.c @@ -3,10 +3,12 @@ */ #include -#include #include #include +#include +#include + #include #include #include @@ -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); +} diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index fce90a112..b9240e7f8 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -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 { diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c index 908e726d1..957792301 100644 --- a/lib/librte_eal/windows/eal_thread.c +++ b/lib/librte_eal/windows/eal_thread.c @@ -11,9 +11,10 @@ #include #include #include -#include +#include #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); +} From patchwork Sat Mar 6 00:04:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 88593 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7A1E4A0547; Sat, 6 Mar 2021 01:05:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 026EC22A32A; Sat, 6 Mar 2021 01:05:14 +0100 (CET) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by mails.dpdk.org (Postfix) with ESMTP id 0EB4C22A32C for ; Sat, 6 Mar 2021 01:05:13 +0100 (CET) Received: by mail-lj1-f179.google.com with SMTP id k12so5168918ljg.9 for ; Fri, 05 Mar 2021 16:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hcF6941jVAuCLclcTM4kYTpSSBaCiWZoxfpG7ZlurO0=; b=lU5qfSeT99ifl19JT+UjUFjjHaq3SxqMVtO9oXmvnk8u4PeTPz8XRqC2XRwv8ba0uc 9+81SAMHue8AV0STBm5RJlVXX79tlYcJXb99KLGd+/pzL5AweOp+6eYHC0evPkrMH4Ka IAjwepY72pl+pywJaUCiteEJEFxtqHUAZ4cYM0DmwaOUR1cLnjbTL/fqBEJz5k5hiH7v C7ZNrFJpmwOX6x3/sB2uALqJuN5WZFit+9fwjk+UybV9vvJe2hxsEA8zFDNMkWoNqzXY f9uG+esN8ixk2b1EFURzpD0AV6Nrn1qDfNEjiA7Op1c+7BZFjMPSMofIa+pP47Qu2BEK qj5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hcF6941jVAuCLclcTM4kYTpSSBaCiWZoxfpG7ZlurO0=; b=fWoe/qJYqbN6Rgdxeq0ND/JsWn7ropxQ+irK2corYk7hiHNXZZ+xY1zDLQ13UrWK11 +DXUDG3RNAbaMS6VgFZE0+md89hd1EFk+B5OSKImL8qtSlpyTqEF9tPxj6FbgPY7ycPP o/qggy0VwOF3h1f9RN28CjKXjE+recCTIsQj+f0dCPabs3qdR0N6JEAXP0Vavqui3UY0 XwkOXLPyE3d2mfZRuxgawrwdRiV5zM4bDGeIEZwInmcQFyxEqvSggQf/Z0rIouvajEhz 0QVj95VfrUdRbwqDvm6oE3IaUGVIflsdemzct0DAoeYpp8NJIF5i3yOOgCKiLXQ/FjHa Dp2w== X-Gm-Message-State: AOAM531RQAjhCTgOgPAL3HH00VAvTadxFxNNNJNlBi6NmeDqqM+MkdwL JAUYvfKIcTsSkhISqAUoR3XLUeloouKPSw== X-Google-Smtp-Source: ABdhPJxEFyGb2APRPKJ5H5K+Zf8PqEuJ7N9If/xrEGUatB/1EOgTdzK1VegCdjPeK+OapE3WiSHGRw== X-Received: by 2002:a2e:9084:: with SMTP id l4mr6543737ljg.498.1614989112351; Fri, 05 Mar 2021 16:05:12 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id s22sm494645ljd.28.2021.03.05.16.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 16:05:11 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Nick Connolly , Khoa To , Dmitry Kozlyuk , Jerin Jacob , Sunil Kumar Kori , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sat, 6 Mar 2021 03:04:58 +0300 Message-Id: <20210306000500.8698-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> References: <20210221142819.6769-1-dmitry.kozliuk@gmail.com> <20210306000500.8698-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" POSIX 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(). Signed-off-by: Dmitry Kozlyuk Acked-by: Khoa To --- 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(-) diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c index 66d6bad1a..db16a34cc 100644 --- a/lib/librte_eal/common/eal_common_lcore.c +++ b/lib/librte_eal/common/eal_common_lcore.c @@ -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; } diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 622c7bc42..230bac9f3 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -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; } diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index 24e27387b..d57bb8ecc 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -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); diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c index 33e419aac..f64ca9496 100644 --- a/lib/librte_eal/common/eal_common_trace_ctf.c +++ b/lib/librte_eal/common/eal_common_trace_ctf.c @@ -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; } diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c index 64f58fb66..e32237b8e 100644 --- a/lib/librte_eal/common/eal_common_trace_utils.c +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -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; } diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index b8a0d2002..323240dd7 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -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_ */ diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 2fc3d6141..162671f9c 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -2,6 +2,8 @@ * Copyright(c) 2019 Intel Corporation */ +#include + #include #include #include @@ -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, From patchwork Sat Mar 6 00:04:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 88594 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 05A08A0547; Sat, 6 Mar 2021 01:05:37 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DF3A422A341; Sat, 6 Mar 2021 01:05:15 +0100 (CET) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by mails.dpdk.org (Postfix) with ESMTP id E6E5F22A30B for ; Sat, 6 Mar 2021 01:05:13 +0100 (CET) Received: by mail-lf1-f44.google.com with SMTP id n16so6840966lfb.4 for ; Fri, 05 Mar 2021 16:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R/C5W283E+pQ5ayzmEE8X/XhCW6z/7JmlAdhB2l9IXU=; b=UrBNpBr+lq4ogC6O9gtXJrsYFsnC0o5Cb3q+cOUL488RKGj36SzCh9bQ93Qt90Mfnb Kl1s4I52DtUfAQcyaaVKRe0ph2korlBj1EH2QQO6wy/5MRLcbvKA89SlqKjQjpd4EadV qKm1f0jey3RTK+uQX0YMghyX0mIRACH39LHIC6qhGhP953/2VQsHyQCInnmep5dGgNck 3YTr8dzBNfukeH9f5k02zlcy8bNo7FQWE98HdRFUaFphvjrl3bp20VDPvx8sfA3wyhAw lh451rZ00q6m5nhh+GIQvOajExF3tomAzVv6IDPNZ12r/rcuNBWOFsvrfbmWTNJMTf7a KFfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/C5W283E+pQ5ayzmEE8X/XhCW6z/7JmlAdhB2l9IXU=; b=YFs1EESeIGxAI6QqDaW56rXQOcKKYt2Re8LmyEOVtYdMexBypw9gJaPgEHjRkaHfgF H5Vwx2lw/gG1EsfPyL0Zbbs/xi5uLyoN24n4fpphnzcioGOMdrWwZAdvmQlkk8w+H65F wip+Chfuiz16AasLdQnai5GePCYADAwu/WmwniYR4jrkXw7mZ4L8qdpe7Mt1IgVvpU0D t+6lNxr07vpoZb77x7M/f4Ag6Bqf7XKsCVPFXIuf7cW7ZcM1Bjk6QWxpwNf5MVGJ8Lki MUrcNo/bPrVHqwTwrCMeQRHo+YKYDBIqcIP746trEUkMvHGBClVHmlUn3RqSBifW9Uap oY9w== X-Gm-Message-State: AOAM530qcxaZc89Jqj+z9PX2c6fO3plzdZmFiOwvqlI0Euso1LzscHEx 9CLn90HFEppw8f8wEwroN2Ej/VpYDMAhdw== X-Google-Smtp-Source: ABdhPJxtJOHSTkLNNNjEwrhlmTR8EQZC5vfw/EuGNvk2092MP6oT3SN+i1EOcvWsyBTocJ65lDUA4g== X-Received: by 2002:a19:7ec5:: with SMTP id z188mr7140321lfc.439.1614989113340; Fri, 05 Mar 2021 16:05:13 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id s22sm494645ljd.28.2021.03.05.16.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 16:05:12 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Nick Connolly , Khoa To , Dmitry Kozlyuk , Bruce Richardson Date: Sat, 6 Mar 2021 03:04:59 +0300 Message-Id: <20210306000500.8698-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> References: <20210221142819.6769-1-dmitry.kozliuk@gmail.com> <20210306000500.8698-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" DPDK code often relies on functions 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. Signed-off-by: Dmitry Kozlyuk --- config/meson.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/meson.build b/config/meson.build index 3cf560b8a..51a49855c 100644 --- a/config/meson.build +++ b/config/meson.build @@ -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') From patchwork Sat Mar 6 00:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 88595 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 333B1A0547; Sat, 6 Mar 2021 01:05:44 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A03522A34D; Sat, 6 Mar 2021 01:05:17 +0100 (CET) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mails.dpdk.org (Postfix) with ESMTP id 201CF22A333 for ; Sat, 6 Mar 2021 01:05:15 +0100 (CET) Received: by mail-lj1-f180.google.com with SMTP id u4so5190477ljh.6 for ; Fri, 05 Mar 2021 16:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mcfdSJWyeF4z+RYkBk4URyhUzLsKML9bNmS3ZaQ1Q2A=; b=kUDcTK1p+YtYU3Rm6cHS/dGrOHcOt7X7TAZZ1l6fJGqbJWRu+E29otOJc1NWuSCsXB 5a8eJ3/rWekWlYV14AHxEJuyhN4X5UvBEd1ags5mFrdCTxJ1Wm+KoMYdVw2WPf4MoMop bci/CUmpXzAv0DJazHy3CkYHEVAJ5Tz1w0p97Bw+vufmCr1dEC1HQMltkrZZV/LMXvHb nzcaN/GESiQdbexxpRyTjabmhAFbWXmeoj2dw4tDWVq40MIC7paBVJ9a0OncMq9dMo+x EWOwuX1t0DFR4TN+UbqT57RsiUSIBiIPW5jr7h/u35+TdMK84FQvYlP00GZCQZ80fRBG 8KnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mcfdSJWyeF4z+RYkBk4URyhUzLsKML9bNmS3ZaQ1Q2A=; b=YLT3LnqzRD8iTOjtuBMN/PhMNuugUjBKXE99XG7omdEsnFYRKYmWEPLudvu68/gRW3 9oazythw/r9fG1DyNYvZFz/qs5d30Qbqx4sR6uGiXZ1wpPVlhEgGQwlGlumUtG4NuKxm zuCqL6l8YEXQvcGg/h3TvytjmqFVxiN8wOBzgj0DfgMLm2jwfeOR+9EGw0wO0Xt0CavR 2/0zaAL3opE8y0KF5WW6Ffanzask1FlIgdcB2jylCmfO81kFL/GUvxRJ2pzXdZU61DwI WhjY9GEQPujpgwjaft5oe9Bqop7FjNO2gVdvhhjaanbk01kdPoIyaSgxuqOS0nLecnqQ Himw== X-Gm-Message-State: AOAM533AzEGh1e/nhLyVT6TDeC5bA0VY+OPbPE3pBI0frNXUHwTYF/S9 gytbGNVLnTkvNfU0zDO4axOEwMweo0Nm1w== X-Google-Smtp-Source: ABdhPJxw4FIS3bIegv1B+MH9hRcDB+F68266YNtjNfLt6YvBywovkwq7QTca3A8TVdV5vUYPqzHFYA== X-Received: by 2002:a2e:a318:: with SMTP id l24mr6693625lje.399.1614989114454; Fri, 05 Mar 2021 16:05:14 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id s22sm494645ljd.28.2021.03.05.16.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 16:05:13 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Nick Connolly , Khoa To , Dmitry Kozlyuk , Olivier Matz , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sat, 6 Mar 2021 03:05:00 +0300 Message-Id: <20210306000500.8698-5-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> References: <20210221142819.6769-1-dmitry.kozliuk@gmail.com> <20210306000500.8698-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Exposing 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(). Signed-off-by: Dmitry Kozlyuk --- 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(-) diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst index 5aa9ed7db..f606186ec 100644 --- a/doc/guides/rel_notes/release_21_05.rst +++ b/doc/guides/rel_notes/release_21_05.rst @@ -84,6 +84,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal/windows: Removed POSIX symbol export from ````. + It has been incorrect and could conflict with consumer POSIX implementations. + ABI Changes ----------- diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 79ea5f98c..49770869b 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -18,10 +18,6 @@ #include "cmdline_private.h" -#ifdef RTE_EXEC_ENV_WINDOWS -#define write _write -#endif - static void cmdline_valid_buffer(struct rdline *rdl, const char *buf, __rte_unused unsigned int size) diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c index 0fe149700..998e8ade2 100644 --- a/lib/librte_cmdline/cmdline_socket.c +++ b/lib/librte_cmdline/cmdline_socket.c @@ -16,10 +16,6 @@ #include "cmdline_private.h" #include "cmdline_socket.h" -#ifdef RTE_EXEC_ENV_WINDOWS -#define open _open -#endif - struct cmdline * cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path) { diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c index 2a10fb823..f86802705 100644 --- a/lib/librte_eal/common/eal_common_errno.c +++ b/lib/librte_eal/common/eal_common_errno.c @@ -15,6 +15,10 @@ #include #include +#ifdef RTE_EXEC_ENV_WINDOWS +#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum) +#endif + RTE_DEFINE_PER_LCORE(int, _rte_errno); const char * diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 230bac9f3..6d4d6ff19 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1936,7 +1936,7 @@ eal_check_common_options(struct internal_config *internal_cfg) RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n"); return -1; } - if (index(eal_get_hugefile_prefix(), '%') != NULL) { + if (strchr(eal_get_hugefile_prefix(), '%') != NULL) { RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" " "option\n"); return -1; diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h index 7ef38ff06..d97e07890 100644 --- a/lib/librte_eal/windows/include/rte_os.h +++ b/lib/librte_eal/windows/include/rte_os.h @@ -11,7 +11,6 @@ * Windows OS. It must not include Windows-specific headers. */ -#include #include #include #include @@ -20,100 +19,36 @@ extern "C" { #endif -/* limits.h replacement, value as in */ -#ifndef PATH_MAX -#define PATH_MAX _MAX_PATH -#endif - -#ifndef sleep -#define sleep(x) Sleep(1000 * (x)) -#endif - -#ifndef strerror_r -#define strerror_r(a, b, c) strerror_s(b, c, a) -#endif - -#ifndef strdup -/* strdup is deprecated in Microsoft libc and _strdup is preferred */ -#define strdup(str) _strdup(str) -#endif - -#ifndef strtok_r -#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr) -#endif - -#ifndef index -#define index(a, b) strchr(a, b) -#endif - -#ifndef rindex -#define rindex(a, b) strrchr(a, b) -#endif - -#ifndef strncasecmp -#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count) -#endif - -#ifndef close -#define close _close -#endif - -#ifndef unlink -#define unlink _unlink -#endif - /* cpu_set macros implementation */ #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2) #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2) #define RTE_CPU_FILL(set) CPU_FILL(set) #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src) -/* as in */ -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++; +/* Allow DPDK to call common functions by POSIX names. */ +#ifdef RTE_BUILD_INTERNAL - *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; -} +#ifndef PATH_MAX +#define PATH_MAX _MAX_PATH +#endif -static inline const char * -eal_strerror(int code) -{ - static char buffer[128]; +#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) - strerror_s(buffer, sizeof(buffer), code); - return buffer; -} +#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) -#ifndef strerror -#define strerror eal_strerror -#endif +#endif /* RTE_BUILD_INTERNAL */ -#endif /* RTE_TOOLCHAIN_GCC */ +/* This is an exception without "rte_" prefix, because Windows does have + * ssize_t, but it's defined in which we avoid to expose. + * If ssize_t is defined in user code, it necessarily has the same type. + */ +typedef long long ssize_t; #ifdef __cplusplus }