diff mbox series

[v12,01/10] eal: add basic threading functions

Message ID 1627925546-29982-2-git-send-email-navasile@linux.microsoft.com (mailing list archive)
State Superseded, archived
Headers show
Series eal: Add EAL API for threading | expand

Checks

Context Check Description
ci/iol-testing fail build patch failure
ci/checkpatch warning coding style issues

Commit Message

Narcisa Ana Maria Vasile Aug. 2, 2021, 5:32 p.m. UTC
From: Narcisa Vasile <navasile@microsoft.com>

Use a portable, type-safe representation for the thread identifier.
Add functions for comparing thread ids and obtaining the thread id
for the current thread.

Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
 lib/eal/common/meson.build            |  1 +
 lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
 lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
 lib/eal/unix/meson.build              |  1 -
 lib/eal/version.map                   |  3 ++
 lib/eal/windows/rte_thread.c          | 17 ++++++++
 6 files changed, 95 insertions(+), 32 deletions(-)
 rename lib/eal/{unix => common}/rte_thread.c (66%)

Comments

Narcisa Ana Maria Vasile Aug. 2, 2021, 9:08 p.m. UTC | #1
On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile wrote:
> From: Narcisa Vasile <navasile@microsoft.com>
> 
> Use a portable, type-safe representation for the thread identifier.
> Add functions for comparing thread ids and obtaining the thread id
> for the current thread.
> 
> Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> ---
>  lib/eal/common/meson.build            |  1 +
>  lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
>  lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
>  lib/eal/unix/meson.build              |  1 -
>  lib/eal/version.map                   |  3 ++
>  lib/eal/windows/rte_thread.c          | 17 ++++++++
>  6 files changed, 95 insertions(+), 32 deletions(-)
>  rename lib/eal/{unix => common}/rte_thread.c (66%)
> 
> diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build

Hello, 

I see the following error on this patch:

ninja: error: loading 'build.ninja': No such file or directory

https://lab.dpdk.org/results/dashboard/patchsets/18090/

Locally, the build succeedes.
How can I see more information about this build error?
Dmitry Kozlyuk Aug. 2, 2021, 9:37 p.m. UTC | #2
+ ci@dpdk.org

2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
> On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile wrote:
> > From: Narcisa Vasile <navasile@microsoft.com>
> > 
> > Use a portable, type-safe representation for the thread identifier.
> > Add functions for comparing thread ids and obtaining the thread id
> > for the current thread.
> > 
> > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > ---
> >  lib/eal/common/meson.build            |  1 +
> >  lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
> >  lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
> >  lib/eal/unix/meson.build              |  1 -
> >  lib/eal/version.map                   |  3 ++
> >  lib/eal/windows/rte_thread.c          | 17 ++++++++
> >  6 files changed, 95 insertions(+), 32 deletions(-)
> >  rename lib/eal/{unix => common}/rte_thread.c (66%)
> > 
> > diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build  
> 
> Hello, 
> 
> I see the following error on this patch:
> 
> ninja: error: loading 'build.ninja': No such file or directory
> 
> https://lab.dpdk.org/results/dashboard/patchsets/18090/
> 
> Locally, the build succeedes.
> How can I see more information about this build error?
Owen Hilyard Aug. 3, 2021, 3:11 p.m. UTC | #3
It seems like meson encountered an error when building

app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of size
> 1.
>
> A full log can be found at
> /home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
> ninja: error: loading 'build.ninja': No such file or directory
>

I can also reproduce the issue building locally (Meson version: 0.58.1):
1. Get the DPDK main branch (f12b844b54f4ea7908ecb08ade04c7366ede031d)
2. apply all patches
3. meson $BUILD_DIR

Meson doesn't really give any extra information aside from that, but
looking at the build file, it looks like one of the fast_tests has no
arguments and at least one is expected.

On Mon, Aug 2, 2021 at 5:37 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
wrote:

> + ci@dpdk.org
>
> 2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
> > On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile wrote:
> > > From: Narcisa Vasile <navasile@microsoft.com>
> > >
> > > Use a portable, type-safe representation for the thread identifier.
> > > Add functions for comparing thread ids and obtaining the thread id
> > > for the current thread.
> > >
> > > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > > ---
> > >  lib/eal/common/meson.build            |  1 +
> > >  lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
> > >  lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
> > >  lib/eal/unix/meson.build              |  1 -
> > >  lib/eal/version.map                   |  3 ++
> > >  lib/eal/windows/rte_thread.c          | 17 ++++++++
> > >  6 files changed, 95 insertions(+), 32 deletions(-)
> > >  rename lib/eal/{unix => common}/rte_thread.c (66%)
> > >
> > > diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build
> >
> > Hello,
> >
> > I see the following error on this patch:
> >
> > ninja: error: loading 'build.ninja': No such file or directory
> >
> > https://lab.dpdk.org/results/dashboard/patchsets/18090/
> >
> > Locally, the build succeedes.
> > How can I see more information about this build error?
>
Dmitry Kozlyuk Aug. 3, 2021, 3:38 p.m. UTC | #4
2021-08-03 11:11 (UTC-0400), Owen Hilyard:
> It seems like meson encountered an error when building
> 
> app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of size
> > 1.
> >
> > A full log can be found at
> > /home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
> > ninja: error: loading 'build.ninja': No such file or directory
> >  
> 
> I can also reproduce the issue building locally (Meson version: 0.58.1):

Meson 0.58+ has a known issue on Windows:
https://github.com/mesonbuild/meson/issues/8981
The last known good version is 0.57.2.

> 1. Get the DPDK main branch (f12b844b54f4ea7908ecb08ade04c7366ede031d)
> 2. apply all patches
> 3. meson $BUILD_DIR
> 
> Meson doesn't really give any extra information aside from that, but
> looking at the build file, it looks like one of the fast_tests has no
> arguments and at least one is expected.
> 
> On Mon, Aug 2, 2021 at 5:37 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> wrote:
> 
> > + ci@dpdk.org
> >
> > 2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:  
> > > On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile wrote:  
> > > > From: Narcisa Vasile <navasile@microsoft.com>
> > > >
> > > > Use a portable, type-safe representation for the thread identifier.
> > > > Add functions for comparing thread ids and obtaining the thread id
> > > > for the current thread.
> > > >
> > > > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > > > ---
> > > >  lib/eal/common/meson.build            |  1 +
> > > >  lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
> > > >  lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
> > > >  lib/eal/unix/meson.build              |  1 -
> > > >  lib/eal/version.map                   |  3 ++
> > > >  lib/eal/windows/rte_thread.c          | 17 ++++++++
> > > >  6 files changed, 95 insertions(+), 32 deletions(-)
> > > >  rename lib/eal/{unix => common}/rte_thread.c (66%)
> > > >
> > > > diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build  
> > >
> > > Hello,
> > >
> > > I see the following error on this patch:
> > >
> > > ninja: error: loading 'build.ninja': No such file or directory
> > >
> > > https://lab.dpdk.org/results/dashboard/patchsets/18090/
> > >
> > > Locally, the build succeedes.
> > > How can I see more information about this build error?  
> >
Owen Hilyard Aug. 3, 2021, 3:57 p.m. UTC | #5
Our windows servers are both running 0.57.1, but all of the *nix hosts are
running 0.58.1. This issue also happens on 0.57.1 and 0.57.2, with the
exact same steps to reproduce.

On Tue, Aug 3, 2021 at 11:38 AM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
wrote:

> 2021-08-03 11:11 (UTC-0400), Owen Hilyard:
> > It seems like meson encountered an error when building
> >
> > app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of
> size
> > > 1.
> > >
> > > A full log can be found at
> > >
> /home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
> > > ninja: error: loading 'build.ninja': No such file or directory
> > >
> >
> > I can also reproduce the issue building locally (Meson version: 0.58.1):
>
> Meson 0.58+ has a known issue on Windows:
> https://github.com/mesonbuild/meson/issues/8981
> The last known good version is 0.57.2.
>
> > 1. Get the DPDK main branch (f12b844b54f4ea7908ecb08ade04c7366ede031d)
> > 2. apply all patches
> > 3. meson $BUILD_DIR
> >
> > Meson doesn't really give any extra information aside from that, but
> > looking at the build file, it looks like one of the fast_tests has no
> > arguments and at least one is expected.
> >
> > On Mon, Aug 2, 2021 at 5:37 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > wrote:
> >
> > > + ci@dpdk.org
> > >
> > > 2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
> > > > On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile
> wrote:
> > > > > From: Narcisa Vasile <navasile@microsoft.com>
> > > > >
> > > > > Use a portable, type-safe representation for the thread identifier.
> > > > > Add functions for comparing thread ids and obtaining the thread id
> > > > > for the current thread.
> > > > >
> > > > > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > > > > ---
> > > > >  lib/eal/common/meson.build            |  1 +
> > > > >  lib/eal/{unix => common}/rte_thread.c | 57
> ++++++++++++++++-----------
> > > > >  lib/eal/include/rte_thread.h          | 48 +++++++++++++++++-----
> > > > >  lib/eal/unix/meson.build              |  1 -
> > > > >  lib/eal/version.map                   |  3 ++
> > > > >  lib/eal/windows/rte_thread.c          | 17 ++++++++
> > > > >  6 files changed, 95 insertions(+), 32 deletions(-)
> > > > >  rename lib/eal/{unix => common}/rte_thread.c (66%)
> > > > >
> > > > > diff --git a/lib/eal/common/meson.build
> b/lib/eal/common/meson.build
> > > >
> > > > Hello,
> > > >
> > > > I see the following error on this patch:
> > > >
> > > > ninja: error: loading 'build.ninja': No such file or directory
> > > >
> > > > https://lab.dpdk.org/results/dashboard/patchsets/18090/
> > > >
> > > > Locally, the build succeedes.
> > > > How can I see more information about this build error?
> > >
>
>
diff mbox series

Patch

diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build
index edfca77779..eda250247b 100644
--- a/lib/eal/common/meson.build
+++ b/lib/eal/common/meson.build
@@ -80,6 +80,7 @@  sources += files(
         'rte_random.c',
         'rte_reciprocal.c',
         'rte_service.c',
+        'rte_thread.c',
         'rte_version.c',
 )
 
diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/common/rte_thread.c
similarity index 66%
rename from lib/eal/unix/rte_thread.c
rename to lib/eal/common/rte_thread.c
index c72d619ec1..92a7451b0a 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/common/rte_thread.c
@@ -1,5 +1,6 @@ 
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2021 Mellanox Technologies, Ltd
+ * Copyright(c) 2021 Microsoft Corporation
  */
 
 #include <errno.h>
@@ -16,25 +17,41 @@  struct eal_tls_key {
 	pthread_key_t thread_index;
 };
 
+rte_thread_t
+rte_thread_self(void)
+{
+	rte_thread_t thread_id;
+
+	thread_id.opaque_id = (uintptr_t)pthread_self();
+
+	return thread_id;
+}
+
+int
+rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
+{
+	return pthread_equal((pthread_t)t1.opaque_id, (pthread_t)t2.opaque_id);
+}
+
 int
 rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))
 {
 	int err;
+	rte_thread_key k;
 
-	*key = malloc(sizeof(**key));
-	if ((*key) == NULL) {
+	k = malloc(sizeof(*k));
+	if (k == NULL) {
 		RTE_LOG(DEBUG, EAL, "Cannot allocate TLS key.\n");
-		rte_errno = ENOMEM;
-		return -1;
+		return EINVAL;
 	}
-	err = pthread_key_create(&((*key)->thread_index), destructor);
-	if (err) {
+	err = pthread_key_create(&(k->thread_index), destructor);
+	if (err != 0) {
 		RTE_LOG(DEBUG, EAL, "pthread_key_create failed: %s\n",
 			 strerror(err));
-		free(*key);
-		rte_errno = ENOEXEC;
-		return -1;
+		free(k);
+		return err;
 	}
+	*key = k;
 	return 0;
 }
 
@@ -43,18 +60,16 @@  rte_thread_key_delete(rte_thread_key key)
 {
 	int err;
 
-	if (!key) {
+	if (key == NULL) {
 		RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
-		rte_errno = EINVAL;
-		return -1;
+		return EINVAL;
 	}
 	err = pthread_key_delete(key->thread_index);
-	if (err) {
+	if (err != 0) {
 		RTE_LOG(DEBUG, EAL, "pthread_key_delete failed: %s\n",
 			 strerror(err));
 		free(key);
-		rte_errno = ENOEXEC;
-		return -1;
+		return err;
 	}
 	free(key);
 	return 0;
@@ -65,17 +80,15 @@  rte_thread_value_set(rte_thread_key key, const void *value)
 {
 	int err;
 
-	if (!key) {
+	if (key == NULL) {
 		RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
-		rte_errno = EINVAL;
-		return -1;
+		return EINVAL;
 	}
 	err = pthread_setspecific(key->thread_index, value);
-	if (err) {
+	if (err != 0) {
 		RTE_LOG(DEBUG, EAL, "pthread_setspecific failed: %s\n",
 			strerror(err));
-		rte_errno = ENOEXEC;
-		return -1;
+		return err;
 	}
 	return 0;
 }
@@ -83,7 +96,7 @@  rte_thread_value_set(rte_thread_key key, const void *value)
 void *
 rte_thread_value_get(rte_thread_key key)
 {
-	if (!key) {
+	if (key == NULL) {
 		RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n");
 		rte_errno = EINVAL;
 		return NULL;
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index 8be8ed8f36..748f64d230 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -1,6 +1,8 @@ 
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2021 Mellanox Technologies, Ltd
+ * Copyright(c) 2021 Microsoft Corporation
  */
+#include <stdint.h>
 
 #include <rte_os.h>
 #include <rte_compat.h>
@@ -20,11 +22,45 @@ 
 extern "C" {
 #endif
 
+#include <sched.h>
+
+/**
+ * Thread id descriptor.
+ */
+typedef struct rte_thread_tag {
+	uintptr_t opaque_id; /**< thread identifier */
+} rte_thread_t;
+
 /**
  * TLS key type, an opaque pointer.
  */
 typedef struct eal_tls_key *rte_thread_key;
 
+/**
+ * Get the id of the calling thread.
+ *
+ * @return
+ *   Return the thread id of the calling thread.
+ */
+__rte_experimental
+rte_thread_t rte_thread_self(void);
+
+/**
+ * Check if 2 thread ids are equal.
+ *
+ * @param t1
+ *   First thread id.
+ *
+ * @param t2
+ *   Second thread id.
+ *
+ * @return
+ *   If the ids are equal, return nonzero.
+ *   Otherwise, return 0.
+ */
+__rte_experimental
+int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);
+
 #ifdef RTE_HAS_CPUSET
 
 /**
@@ -63,9 +99,7 @@  void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
  *
  * @return
  *   On success, zero.
- *   On failure, a negative number and an error number is set in rte_errno.
- *   rte_errno can be: ENOMEM  - Memory allocation error.
- *                     ENOEXEC - Specific OS error.
+ *   On failure, return a positive errno-style error number.
  */
 
 __rte_experimental
@@ -80,9 +114,7 @@  int rte_thread_key_create(rte_thread_key *key,
  *
  * @return
  *   On success, zero.
- *   On failure, a negative number and an error number is set in rte_errno.
- *   rte_errno can be: EINVAL  - Invalid parameter passed.
- *                     ENOEXEC - Specific OS error.
+ *   On failure, return a positive errno-style error number.
  */
 __rte_experimental
 int rte_thread_key_delete(rte_thread_key key);
@@ -97,9 +129,7 @@  int rte_thread_key_delete(rte_thread_key key);
  *
  * @return
  *   On success, zero.
- *   On failure, a negative number and an error number is set in rte_errno.
- *   rte_errno can be: EINVAL  - Invalid parameter passed.
- *                     ENOEXEC - Specific OS error.
+ *   On failure, return a positive errno-style error number.
  */
 __rte_experimental
 int rte_thread_value_set(rte_thread_key key, const void *value);
diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build
index e3ecd3e956..cb6d233721 100644
--- a/lib/eal/unix/meson.build
+++ b/lib/eal/unix/meson.build
@@ -6,5 +6,4 @@  sources += files(
         'eal_unix_memory.c',
         'eal_unix_timer.c',
         'eal_firmware.c',
-        'rte_thread.c',
 )
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 887012d02a..ba7dcda664 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -426,6 +426,9 @@  EXPERIMENTAL {
 
 	# added in 21.08
 	rte_power_monitor_multi; # WINDOWS_NO_EXPORT
+
+	rte_thread_self;
+	rte_thread_equal;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 667287c387..41c354818b 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -1,5 +1,6 @@ 
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2021 Mellanox Technologies, Ltd
+ * Copyright(c) 2021 Microsoft Corporation
  */
 
 #include <rte_common.h>
@@ -11,6 +12,22 @@  struct eal_tls_key {
 	DWORD thread_index;
 };
 
+rte_thread_t
+rte_thread_self(void)
+{
+	rte_thread_t thread_id;
+
+	thread_id.opaque_id = GetCurrentThreadId();
+
+	return thread_id;
+}
+
+int
+rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
+{
+	return t1.opaque_id == t2.opaque_id;
+}
+
 int
 rte_thread_key_create(rte_thread_key *key,
 		__rte_unused void (*destructor)(void *))