DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v2] eal/linux: enhanced error handling for affinity
@ 2024-04-25 11:11 Jianyue Wu
  2024-04-26 15:47 ` Tyler Retzlaff
  0 siblings, 1 reply; 6+ messages in thread
From: Jianyue Wu @ 2024-04-25 11:11 UTC (permalink / raw)
  To: stephen, ferruh.yigit, dev; +Cc: Jianyue Wu

From: Jianyue Wu <jianyue.wu@nokia-sbell.com>

Improve the robustness of setting thread affinity in DPDK
by adding detailed error logging.

Changes:
1. Check the return value of pthread_setaffinity_np() and log an error
if the call fails.
2. Include the current thread name, the intended CPU set, and a detailed
error message in the log.

Sample prints:
EAL: Cannot set affinity for thread dpdk-test with cpus 0,
ret: 22, errno: 0, error description: Success
EAL: Cannot set affinity for thread dpdk-worker1 with cpus 1,
ret: 22, errno: 0, error description: Success

Signed-off-by: Jianyue Wu <jianyue.wu@nokia-sbell.com>
---
 lib/eal/common/eal_common_thread.c |  2 +-
 lib/eal/common/eal_thread.h        |  2 +-
 lib/eal/unix/rte_thread.c          | 27 +++++++++++++++++++++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index a53bc639ae..31a2fab2a7 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -103,7 +103,7 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp)
 }
 
 int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size)
+eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size)
 {
 	unsigned cpu;
 	int ret;
diff --git a/lib/eal/common/eal_thread.h b/lib/eal/common/eal_thread.h
index 1c3c3442d3..85ab84baa5 100644
--- a/lib/eal/common/eal_thread.h
+++ b/lib/eal/common/eal_thread.h
@@ -50,7 +50,7 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);
  *   0 for success, -1 if truncation happens.
  */
 int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
+eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size);
 
 /**
  * Dump the current thread cpuset.
diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e..34ac0eabbf 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -369,8 +369,31 @@ int
 rte_thread_set_affinity_by_id(rte_thread_t thread_id,
 		const rte_cpuset_t *cpuset)
 {
-	return pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
-		sizeof(*cpuset), cpuset);
+	int ret;
+#if defined(__linux__) && defined(_GNU_SOURCE)
+	char cpus_str[RTE_CPU_AFFINITY_STR_LEN] = {'\0'};
+	char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'};
+	errno = 0;
+#endif
+
+	ret = pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
+				sizeof(*cpuset), cpuset);
+
+#if defined(__linux__) && defined(_GNU_SOURCE)
+	if (ret != 0) {
+		if (pthread_getname_np((pthread_t)thread_id.opaque_id,
+					thread_name, sizeof(thread_name)) != 0)
+			EAL_LOG(ERR, "pthread_getname_np failed!");
+		if (eal_thread_dump_affinity(cpuset, cpus_str, RTE_CPU_AFFINITY_STR_LEN) != 0)
+			EAL_LOG(ERR, "eal_thread_dump_affinity failed!");
+		EAL_LOG(ERR, "Cannot set affinity for thread %s with cpus %s, "
+			"ret: %d, errno: %d, error description: %s",
+			thread_name, cpus_str,
+			ret, errno, strerror(errno));
+	}
+#endif
+
+	return ret;
 }
 
 int
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] eal/linux: enhanced error handling for affinity
  2024-04-25 11:11 [PATCH v2] eal/linux: enhanced error handling for affinity Jianyue Wu
@ 2024-04-26 15:47 ` Tyler Retzlaff
  2024-04-27  0:18   ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Tyler Retzlaff @ 2024-04-26 15:47 UTC (permalink / raw)
  To: Jianyue Wu; +Cc: stephen, ferruh.yigit, dev, Jianyue Wu

On Thu, Apr 25, 2024 at 07:11:30PM +0800, Jianyue Wu wrote:
> From: Jianyue Wu <jianyue.wu@nokia-sbell.com>
> 
> Improve the robustness of setting thread affinity in DPDK
> by adding detailed error logging.
> 
> Changes:
> 1. Check the return value of pthread_setaffinity_np() and log an error
> if the call fails.
> 2. Include the current thread name, the intended CPU set, and a detailed
> error message in the log.
> 
> Sample prints:
> EAL: Cannot set affinity for thread dpdk-test with cpus 0,
> ret: 22, errno: 0, error description: Success
> EAL: Cannot set affinity for thread dpdk-worker1 with cpus 1,
> ret: 22, errno: 0, error description: Success
> 
> Signed-off-by: Jianyue Wu <jianyue.wu@nokia-sbell.com>
> ---
>  lib/eal/common/eal_common_thread.c |  2 +-
>  lib/eal/common/eal_thread.h        |  2 +-
>  lib/eal/unix/rte_thread.c          | 27 +++++++++++++++++++++++++--
>  3 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
> index a53bc639ae..31a2fab2a7 100644
> --- a/lib/eal/common/eal_common_thread.c
> +++ b/lib/eal/common/eal_common_thread.c
> @@ -103,7 +103,7 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp)
>  }
>  
>  int
> -eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size)
> +eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size)
>  {
>  	unsigned cpu;
>  	int ret;
> diff --git a/lib/eal/common/eal_thread.h b/lib/eal/common/eal_thread.h
> index 1c3c3442d3..85ab84baa5 100644
> --- a/lib/eal/common/eal_thread.h
> +++ b/lib/eal/common/eal_thread.h
> @@ -50,7 +50,7 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);
>   *   0 for success, -1 if truncation happens.
>   */
>  int
> -eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
> +eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size);

no objection to adding const

>  
>  /**
>   * Dump the current thread cpuset.
> diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
> index 1b4c73f58e..34ac0eabbf 100644
> --- a/lib/eal/unix/rte_thread.c
> +++ b/lib/eal/unix/rte_thread.c
> @@ -369,8 +369,31 @@ int
>  rte_thread_set_affinity_by_id(rte_thread_t thread_id,
>  		const rte_cpuset_t *cpuset)
>  {
> -	return pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
> -		sizeof(*cpuset), cpuset);
> +	int ret;
> +#if defined(__linux__) && defined(_GNU_SOURCE)
> +	char cpus_str[RTE_CPU_AFFINITY_STR_LEN] = {'\0'};
> +	char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'};
> +	errno = 0;
> +#endif
> +
> +	ret = pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
> +				sizeof(*cpuset), cpuset);
> +
> +#if defined(__linux__) && defined(_GNU_SOURCE)
> +	if (ret != 0) {
> +		if (pthread_getname_np((pthread_t)thread_id.opaque_id,
> +					thread_name, sizeof(thread_name)) != 0)
> +			EAL_LOG(ERR, "pthread_getname_np failed!");
> +		if (eal_thread_dump_affinity(cpuset, cpus_str, RTE_CPU_AFFINITY_STR_LEN) != 0)
> +			EAL_LOG(ERR, "eal_thread_dump_affinity failed!");
> +		EAL_LOG(ERR, "Cannot set affinity for thread %s with cpus %s, "
> +			"ret: %d, errno: %d, error description: %s",
> +			thread_name, cpus_str,
> +			ret, errno, strerror(errno));
> +	}
> +#endif
> +
> +	return ret;
>  }
>  
>  int
> -- 

i do not think introducing os specific behavior/logging to the EAL
is a good idea. logging although not formally part of the api surface
should present the same experience for all platforms. the EAL should
have a higher standard here.

> 2.34.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] eal/linux: enhanced error handling for affinity
  2024-04-26 15:47 ` Tyler Retzlaff
@ 2024-04-27  0:18   ` Stephen Hemminger
  2024-04-28 12:26     ` Jianyue Wu
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2024-04-27  0:18 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: Jianyue Wu, ferruh.yigit, dev, Jianyue Wu

On Fri, 26 Apr 2024 08:47:37 -0700
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> >  int
> > --   
> 
> i do not think introducing os specific behavior/logging to the EAL
> is a good idea. logging although not formally part of the api surface
> should present the same experience for all platforms. the EAL should
> have a higher standard here.
> 
> > 2.34.1  

For this case, the error message would be better if there was some way
to look at the cgroups and mark the cores that are not available as if
they were offline lcores.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:Re: [PATCH v2] eal/linux: enhanced error handling for affinity
  2024-04-27  0:18   ` Stephen Hemminger
@ 2024-04-28 12:26     ` Jianyue Wu
  0 siblings, 0 replies; 6+ messages in thread
From: Jianyue Wu @ 2024-04-28 12:26 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Tyler Retzlaff, ferruh.yigit, dev, jianyue.wu

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

Yes, agree with that, there is also trace from kernel can see that. I'll ignore this patch.


At 2024-04-27 08:18:53, "Stephen Hemminger" <stephen@networkplumber.org> wrote:
>On Fri, 26 Apr 2024 08:47:37 -0700
>Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
>
>> >  int
>> > --   
>> 
>> i do not think introducing os specific behavior/logging to the EAL
>> is a good idea. logging although not formally part of the api surface
>> should present the same experience for all platforms. the EAL should
>> have a higher standard here.
>> 
>> > 2.34.1  
>
>For this case, the error message would be better if there was some way
>to look at the cgroups and mark the cores that are not available as if
>they were offline lcores.
>
>

[-- Attachment #2: Type: text/html, Size: 988 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] eal/linux: enhanced error handling for affinity
  2024-04-22 13:23   ` [PATCH] eal/linux: enhanced error handling for affinity Jianyue Wu (NSB)
@ 2024-04-24  5:45     ` Jianyue Wu (NSB)
  0 siblings, 0 replies; 6+ messages in thread
From: Jianyue Wu (NSB) @ 2024-04-24  5:45 UTC (permalink / raw)
  To: roretzla, thomas, david.marchand, ferruh.yigit; +Cc: 'dev@dpdk.org'


[-- Attachment #1.1: Type: text/plain, Size: 1079 bytes --]

Hello,

I've noticed some coding style issues eal/linux: enhanced error handling for affinity - Patchwork (dpdk.org)<https://patches.dpdk.org/project/dpdk/patch/20240422134917.3740545-1-ferruh.yigit@amd.com/> and have attempted to update the patch accordingly. Could you please help by updating it with version 2 of the patch? Thank you very much! 😊

Thank you~
Best regards,
Dave

From: Jianyue Wu (NSB)
Sent: 2024年4月22日 21:24
To: 'roretzla@linux.microsoft.com' <roretzla@linux.microsoft.com>; 'thomas@monjalon.net' <thomas@monjalon.net>; 'david.marchand@redhat.com' <david.marchand@redhat.com>
Cc: 'dev@dpdk.org' <dev@dpdk.org>
Subject: [PATCH] eal/linux: enhanced error handling for affinity

Hello,

Good day~
I hope this message finds you well. I am writing to submit a patch for consideration, which primarily adds enhanced error handling for affinity sets within the eal/linux of DPDK. Unfortunately, my current environment does not support git send-email, so I am sending this patch attached to this email.

Thank you~
Best regards,
Dave


[-- Attachment #1.2: Type: text/html, Size: 5539 bytes --]

[-- Attachment #2: 0001-eal-linux-enhanced-error-handling-for-affinity.patch --]
[-- Type: application/octet-stream, Size: 2035 bytes --]

From bc7ed0f08373b0159a5990511f15312815bf36bd Mon Sep 17 00:00:00 2001
From: Jianyue Wu <jianyue.wu@nokia-sbell.com>
Date: Fri, 19 Apr 2024 13:57:35 +0300
Subject: [PATCH v2] eal/linux: enhanced error handling for affinity

Improve the robustness of setting thread affinity in DPDK
by adding detailed error logging.

Changes:
1. Check the return value of pthread_setaffinity_np() and log an error
if the call fails.
2. Include the current thread name, the intended CPU set, and a detailed
error message in the log.

Sample prints:
EAL: Cannot set affinity for thread dpdk-test with cpus 0,
ret: 22, errno: 0, error description: Success
EAL: Cannot set affinity for thread dpdk-worker1 with cpus 1,
ret: 22, errno: 0, error description: Success

Signed-off-by: Jianyue Wu <jianyue.wu@nokia-sbell.com>
---
 lib/eal/unix/rte_thread.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e..8f9eaf0dcf 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -369,8 +369,26 @@ int
 rte_thread_set_affinity_by_id(rte_thread_t thread_id,
 		const rte_cpuset_t *cpuset)
 {
-	return pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
-		sizeof(*cpuset), cpuset);
+	int ret;
+	char cpus_str[RTE_CPU_AFFINITY_STR_LEN] = {'\0'};
+	char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'};
+
+	errno = 0;
+	ret = pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
+				sizeof(*cpuset), cpuset);
+	if (ret != 0) {
+		if (pthread_getname_np((pthread_t)thread_id.opaque_id,
+					thread_name, sizeof(thread_name)) != 0)
+			EAL_LOG(ERR, "pthread_getname_np failed!");
+		if (eal_thread_dump_affinity(cpuset, cpus_str, RTE_CPU_AFFINITY_STR_LEN) != 0)
+			EAL_LOG(ERR, "eal_thread_dump_affinity failed!");
+		EAL_LOG(ERR, "Cannot set affinity for thread %s with cpus %s, "
+			"ret: %d, errno: %d, error description: %s",
+			thread_name, cpus_str,
+			ret, errno, strerror(errno));
+	}
+
+	return ret;
 }
 
 int
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] eal/linux: enhanced error handling for affinity
@ 2024-04-23  5:20 Jianyue Wu
  0 siblings, 0 replies; 6+ messages in thread
From: Jianyue Wu @ 2024-04-23  5:20 UTC (permalink / raw)
  Cc: dev, Jianyue Wu

Improve the robustness of setting thread affinity in DPDK
by adding detailed error logging.

Changes:
1. Check the return value of pthread_setaffinity_np() and log an error
if the call fails.
2. Include the current thread name, the intended CPU set, and a detailed
error message in the log.

Sample prints:
EAL: Cannot set affinity for thread dpdk-test with cpus 0,
ret: 22, errno: 0, error description: Success
EAL: Cannot set affinity for thread dpdk-worker1 with cpus 1,
ret: 22, errno: 0, error description: Success

Signed-off-by: Jianyue Wu <wujianyue000@163.com>
---
 lib/eal/common/eal_common_thread.c |  2 +-
 lib/eal/common/eal_thread.h        |  2 +-
 lib/eal/unix/rte_thread.c          | 22 ++++++++++++++++++++--
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index a53bc639ae..31a2fab2a7 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -103,7 +103,7 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp)
 }
 
 int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size)
+eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size)
 {
 	unsigned cpu;
 	int ret;
diff --git a/lib/eal/common/eal_thread.h b/lib/eal/common/eal_thread.h
index 1c3c3442d3..85ab84baa5 100644
--- a/lib/eal/common/eal_thread.h
+++ b/lib/eal/common/eal_thread.h
@@ -50,7 +50,7 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);
  *   0 for success, -1 if truncation happens.
  */
 int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
+eal_thread_dump_affinity(const rte_cpuset_t *cpuset, char *str, unsigned int size);
 
 /**
  * Dump the current thread cpuset.
diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e..8f9eaf0dcf 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -369,8 +369,26 @@ int
 rte_thread_set_affinity_by_id(rte_thread_t thread_id,
 		const rte_cpuset_t *cpuset)
 {
-	return pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
-		sizeof(*cpuset), cpuset);
+	int ret;
+	char cpus_str[RTE_CPU_AFFINITY_STR_LEN] = {'\0'};
+	char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'};
+
+	errno = 0;
+	ret = pthread_setaffinity_np((pthread_t)thread_id.opaque_id,
+				sizeof(*cpuset), cpuset);
+	if (ret != 0) {
+		if (pthread_getname_np((pthread_t)thread_id.opaque_id,
+					thread_name, sizeof(thread_name)) != 0)
+			EAL_LOG(ERR, "pthread_getname_np failed!");
+		if (eal_thread_dump_affinity(cpuset, cpus_str, RTE_CPU_AFFINITY_STR_LEN) != 0)
+			EAL_LOG(ERR, "eal_thread_dump_affinity failed!");
+		EAL_LOG(ERR, "Cannot set affinity for thread %s with cpus %s, "
+			"ret: %d, errno: %d, error description: %s",
+			thread_name, cpus_str,
+			ret, errno, strerror(errno));
+	}
+
+	return ret;
 }
 
 int
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-29  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 11:11 [PATCH v2] eal/linux: enhanced error handling for affinity Jianyue Wu
2024-04-26 15:47 ` Tyler Retzlaff
2024-04-27  0:18   ` Stephen Hemminger
2024-04-28 12:26     ` Jianyue Wu
  -- strict thread matches above, loose matches on Subject: below --
2024-04-23  5:20 Jianyue Wu
2021-06-09 11:25 [dpdk-dev] Does memif support primary<->secondary process communication? Wu, Jianyue (NSB - CN/Hangzhou)
2021-06-09 12:07 ` Wu, Jianyue (NSB - CN/Hangzhou)
2024-04-22 13:23   ` [PATCH] eal/linux: enhanced error handling for affinity Jianyue Wu (NSB)
2024-04-24  5:45     ` [PATCH v2] " Jianyue Wu (NSB)

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).