From: Tal Shnaiderman <talshn@nvidia.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, pallavi.kadam@intel.com,
dmitry.kozliuk@gmail.com, navasile@linux.microsoft.com,
dmitrym@microsoft.com, david.marchand@redhat.com,
anatoly.burakov@intel.com, vladimir.medvedkin@intel.com,
mb@smartsharesystems.com
Subject: [dpdk-dev] [PATCH v4 1/2] eal: error number enhancement for thread TLS API
Date: Wed, 10 Mar 2021 14:48:55 +0200 [thread overview]
Message-ID: <20210310124856.8188-2-talshn@nvidia.com> (raw)
In-Reply-To: <20210310124856.8188-1-talshn@nvidia.com>
add error number reporting to rte_errno in all
functions in the rte_thread_tls_* API.
Suggested-by: Anatoly Burakov <anatoly.burakov@intel.com>
Signed-off-by: Tal Shnaiderman <talshn@nvidia.com>
---
lib/librte_eal/include/rte_thread.h | 14 +++++++++++---
lib/librte_eal/unix/rte_thread.c | 6 ++++++
lib/librte_eal/windows/rte_thread.c | 6 ++++++
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h
index e640ea1857..7a503b81c9 100644
--- a/lib/librte_eal/include/rte_thread.h
+++ b/lib/librte_eal/include/rte_thread.h
@@ -59,7 +59,9 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
*
* @return
* On success, zero.
- * On failure, a negative number.
+ * On failure, a negative number and an error number is set in rte_errno.
+ * rte_errno can be set to: ENOMEM - Memory allocation error.
+ * ENOEXEC - Specific OS error.
*/
__rte_experimental
@@ -73,7 +75,9 @@ int rte_thread_tls_key_create(rte_tls_key *key, void (*destructor)(void *));
*
* @return
* On success, zero.
- * On failure, a negative number.
+ * On failure, a negative number and an error number is set in rte_errno.
+ * rte_errno can be set to: EINVAL - Invalid parameter passed.
+ * ENOEXEC - Specific OS error.
*/
__rte_experimental
int rte_thread_tls_key_delete(rte_tls_key key);
@@ -88,7 +92,9 @@ int rte_thread_tls_key_delete(rte_tls_key key);
*
* @return
* On success, zero.
- * On failure, a negative number.
+ * On failure, a negative number and an error number is set in rte_errno.
+ * rte_errno can be set to: EINVAL - Invalid parameter passed.
+ * ENOEXEC - Specific OS error.
*/
__rte_experimental
int rte_thread_tls_value_set(rte_tls_key key, const void *value);
@@ -102,6 +108,8 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);
* @return
* On success, value data pointer (can also be NULL).
* On failure, NULL and an error number is set in rte_errno.
+ * rte_errno can be set to: EINVAL - Invalid parameter passed.
+ * ENOEXEC - Specific OS error.
*/
__rte_experimental
void *rte_thread_tls_value_get(rte_tls_key key);
diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c
index 86ffeebc95..b187c69a4c 100644
--- a/lib/librte_eal/unix/rte_thread.c
+++ b/lib/librte_eal/unix/rte_thread.c
@@ -24,6 +24,7 @@ rte_thread_tls_key_create(rte_tls_key *key, void (*destructor)(void *))
*key = malloc(sizeof(**key));
if ((*key) == NULL) {
RTE_LOG(DEBUG, EAL, "Cannot allocate TLS key.\n");
+ rte_errno = ENOMEM;
return -1;
}
err = pthread_key_create(&((*key)->thread_index), destructor);
@@ -31,6 +32,7 @@ rte_thread_tls_key_create(rte_tls_key *key, void (*destructor)(void *))
RTE_LOG(DEBUG, EAL, "pthread_key_create failed: %s\n",
strerror(err));
free(*key);
+ rte_errno = ENOEXEC;
return -1;
}
return 0;
@@ -43,6 +45,7 @@ rte_thread_tls_key_delete(rte_tls_key key)
if (!key) {
RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
+ rte_errno = EINVAL;
return -1;
}
err = pthread_key_delete(key->thread_index);
@@ -50,6 +53,7 @@ rte_thread_tls_key_delete(rte_tls_key key)
RTE_LOG(DEBUG, EAL, "pthread_key_delete failed: %s\n",
strerror(err));
free(key);
+ rte_errno = ENOEXEC;
return -1;
}
free(key);
@@ -63,12 +67,14 @@ rte_thread_tls_value_set(rte_tls_key key, const void *value)
if (!key) {
RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
+ rte_errno = EINVAL;
return -1;
}
err = pthread_setspecific(key->thread_index, value);
if (err) {
RTE_LOG(DEBUG, EAL, "pthread_setspecific failed: %s\n",
strerror(err));
+ rte_errno = ENOEXEC;
return -1;
}
return 0;
diff --git a/lib/librte_eal/windows/rte_thread.c b/lib/librte_eal/windows/rte_thread.c
index 2e2ab29177..fa9e360855 100644
--- a/lib/librte_eal/windows/rte_thread.c
+++ b/lib/librte_eal/windows/rte_thread.c
@@ -18,12 +18,14 @@ rte_thread_tls_key_create(rte_tls_key *key,
*key = malloc(sizeof(**key));
if ((*key) == NULL) {
RTE_LOG(DEBUG, EAL, "Cannot allocate TLS key.\n");
+ rte_errno = ENOMEM;
return -1;
}
(*key)->thread_index = TlsAlloc();
if ((*key)->thread_index == TLS_OUT_OF_INDEXES) {
RTE_LOG_WIN32_ERR("TlsAlloc()");
free(*key);
+ rte_errno = ENOEXEC;
return -1;
}
return 0;
@@ -34,11 +36,13 @@ rte_thread_tls_key_delete(rte_tls_key key)
{
if (!key) {
RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
+ rte_errno = EINVAL;
return -1;
}
if (!TlsFree(key->thread_index)) {
RTE_LOG_WIN32_ERR("TlsFree()");
free(key);
+ rte_errno = ENOEXEC;
return -1;
}
free(key);
@@ -52,12 +56,14 @@ rte_thread_tls_value_set(rte_tls_key key, const void *value)
if (!key) {
RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
+ rte_errno = EINVAL;
return -1;
}
/* discard const qualifier */
p = (char *) (uintptr_t) value;
if (!TlsSetValue(key->thread_index, p)) {
RTE_LOG_WIN32_ERR("TlsSetValue()");
+ rte_errno = ENOEXEC;
return -1;
}
return 0;
--
2.16.1.windows.4
next prev parent reply other threads:[~2021-03-10 12:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 15:26 [dpdk-dev] [PATCH v2 0/2] EAL Thread TLS API enhancements Tal Shnaiderman
2021-03-02 15:26 ` [dpdk-dev] [PATCH v2 1/2] eal: error number enhancement for thread TLS API Tal Shnaiderman
2021-03-02 17:09 ` Dmitry Kozlyuk
2021-03-03 10:37 ` Tal Shnaiderman
2021-03-03 11:10 ` Dmitry Kozlyuk
2021-03-03 11:53 ` Tal Shnaiderman
2021-03-10 12:06 ` [dpdk-dev] [PATCH v3 0/2] EAL Thread TLS API enhancements Tal Shnaiderman
2021-03-10 12:06 ` [dpdk-dev] [PATCH v3 1/2] eal: error number enhancement for thread TLS API Tal Shnaiderman
2021-03-10 12:48 ` [dpdk-dev] [PATCH v4 0/2] EAL Thread TLS API enhancements Tal Shnaiderman
2021-03-10 12:48 ` Tal Shnaiderman [this message]
2021-03-10 19:45 ` [dpdk-dev] [PATCH v4 1/2] eal: error number enhancement for thread TLS API Narcisa Ana Maria Vasile
2021-03-15 15:37 ` Tal Shnaiderman
2021-03-13 2:29 ` Dmitry Kozlyuk
2021-03-15 23:14 ` Thomas Monjalon
2021-03-16 9:15 ` [dpdk-dev] [PATCH v5 0/2] EAL Thread TLS API enhancements Tal Shnaiderman
2021-03-16 9:15 ` [dpdk-dev] [PATCH v5 1/2] eal: error number enhancement for thread TLS API Tal Shnaiderman
2021-03-16 13:28 ` [dpdk-dev] [PATCH v6 0/2] EAL Thread TLS API enhancements Tal Shnaiderman
2021-03-16 13:28 ` [dpdk-dev] [PATCH v6 1/2] eal: error number enhancement for thread TLS API Tal Shnaiderman
2021-03-16 13:28 ` [dpdk-dev] [PATCH v6 2/2] eal: rename key opaque pointer and functions in " Tal Shnaiderman
2021-03-26 8:24 ` [dpdk-dev] [PATCH v6 0/2] EAL Thread TLS API enhancements Thomas Monjalon
2021-03-16 9:15 ` [dpdk-dev] [PATCH v5 2/2] eal: rename key opaque pointer and functions in TLS API Tal Shnaiderman
2021-03-10 12:48 ` [dpdk-dev] [PATCH v4 " Tal Shnaiderman
2021-03-15 23:16 ` Thomas Monjalon
2021-03-16 9:17 ` Tal Shnaiderman
2021-03-10 12:06 ` [dpdk-dev] [PATCH v3 " Tal Shnaiderman
2021-03-10 12:22 ` Morten Brørup
2021-03-02 15:26 ` [dpdk-dev] [PATCH v2 2/2] eal: rename key opaque pointer " Tal Shnaiderman
2021-03-02 15:36 ` Morten Brørup
2021-03-04 11:16 ` Tal Shnaiderman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210310124856.8188-2-talshn@nvidia.com \
--to=talshn@nvidia.com \
--cc=anatoly.burakov@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=dmitry.kozliuk@gmail.com \
--cc=dmitrym@microsoft.com \
--cc=mb@smartsharesystems.com \
--cc=navasile@linux.microsoft.com \
--cc=pallavi.kadam@intel.com \
--cc=thomas@monjalon.net \
--cc=vladimir.medvedkin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).