DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] Does memif support primary<->secondary process communication?
@ 2021-06-09 11:25 Wu, Jianyue (NSB - CN/Hangzhou)
  2021-06-09 12:07 ` Wu, Jianyue (NSB - CN/Hangzhou)
  0 siblings, 1 reply; 14+ messages in thread
From: Wu, Jianyue (NSB - CN/Hangzhou) @ 2021-06-09 11:25 UTC (permalink / raw)
  To: users, dev

Hello,

May I ask a question about memif?
When I'm trying to develop a communication mechanism for two processes, which also need to share memzones between the processes, so need primary<->secondary.
https://doc.dpdk.org/guides/nics/memif.html
But from the guideline, it seems always use primary<->primary. Does it support primary<->secondary? Thanks indeed in advance!

Best Regards,
Dave(Jianyue)


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

* Re: [dpdk-dev] Does memif support primary<->secondary process communication?
  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)
  0 siblings, 1 reply; 14+ messages in thread
From: Wu, Jianyue (NSB - CN/Hangzhou) @ 2021-06-09 12:07 UTC (permalink / raw)
  To: users, dev

BTW, I use it for primary and secondary communication, so that will use memif to share data between primary and secondary. Thanks.

Best Regards,
Dave(Jianyue)

From: Wu, Jianyue (NSB - CN/Hangzhou)
Sent: 2021年6月9日 19:26
To: users@dpdk.org; 'dev@dpdk.org' <dev@dpdk.org>
Subject: Does memif support primary<->secondary process communication?

Hello,

May I ask a question about memif?
When I’m trying to develop a communication mechanism for two processes, which also need to share memzones between the processes, so need primary<->secondary.
https://doc.dpdk.org/guides/nics/memif.html
But from the guideline, it seems always use primary<->primary. Does it support primary<->secondary? Thanks indeed in advance!

Best Regards,
Dave(Jianyue)


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

* [PATCH] eal/linux: enhanced error handling for affinity
  2021-06-09 12:07 ` Wu, Jianyue (NSB - CN/Hangzhou)
@ 2024-04-22 13:23   ` Jianyue Wu (NSB)
  2024-04-22 13:49     ` Ferruh Yigit
                       ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Jianyue Wu (NSB) @ 2024-04-22 13:23 UTC (permalink / raw)
  To: roretzla, thomas, david.marchand; +Cc: 'dev@dpdk.org'


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

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: 3047 bytes --]

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

From 89d879f762dc5e6901fc6cde06b8c36b641424de 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] eal/linux: enhanced error handling for affinity

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

Changes:
1. Set `errno` to 0 before calling `pthread_setaffinity_np()` to ensure
clean error status.
2. Check the return value of `pthread_setaffinity_np()` and log an error
if the call fails.
3. 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 | 51 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e..56bc7995eb 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -5,6 +5,7 @@
 
 #include <errno.h>
 #include <pthread.h>
+#include <sched.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
@@ -114,6 +115,35 @@ thread_start_wrapper(void *arg)
 	return (void *)(uintptr_t)thread_func(thread_args);
 }
 
+/* Function to convert cpu_set_t to a string. */
+static void cpuset_to_string(const cpu_set_t *cpuset,
+			char *cpus_str, size_t cpus_str_size) {
+	int cpu;
+	// Track the current position in the string
+	size_t offset = 0;
+
+	// Clear the string buffer
+	memset(cpus_str, 0, cpus_str_size);
+	cpus_str_size = RTE_MAX_LCORE < cpus_str_size ?
+		RTE_MAX_LCORE : cpus_str_size;
+
+	// Iterate over each CPU core, and check if it is included in the set
+	for (cpu = 0; cpu < RTE_MAX_LCORE && offset < cpus_str_size - 1; ++cpu) {
+		if (CPU_ISSET(cpu, cpuset)) {
+			// Append the current CPU number to the string
+			int written = snprintf(cpus_str + offset, cpus_str_size - offset,
+				"%s%d", (offset > 0 ? "," : ""), cpu);
+			if (written > 0)
+				offset += written;
+			if (offset >= cpus_str_size - 1)
+				break;
+			}
+	}
+
+	// Ensure the string is properly terminated
+	cpus_str[cpus_str_size - 1] = '\0';
+}
+
 int
 rte_thread_create(rte_thread_t *thread_id,
 		const rte_thread_attr_t *thread_attr,
@@ -369,8 +399,25 @@ 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_MAX_LCORE + 1] = {'\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!");
+		cpuset_to_string(cpuset, cpus_str, sizeof(cpus_str));
+		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.42.0


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

* [PATCH] 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-22 13:49     ` Ferruh Yigit
  2024-04-26 21:31       ` Patrick Robb
  2024-04-22 13:50     ` Ferruh Yigit
                       ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Ferruh Yigit @ 2024-04-22 13:49 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, David Marchand, roretzla, 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. Set `errno` to 0 before calling `pthread_setaffinity_np()` to ensure
clean error status.
2. Check the return value of `pthread_setaffinity_np()` and log an error
if the call fails.
3. 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>
---
 .mailmap                  |  1 +
 lib/eal/unix/rte_thread.c | 51 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/.mailmap b/.mailmap
index 3843868716bd..66cff91f30a9 100644
--- a/.mailmap
+++ b/.mailmap
@@ -639,6 +639,7 @@ Jianfeng Tan <jianfeng.tan@intel.com>
 Jiangu Zhao <zhaojg@arraynetworks.com.cn>
 Jianwei Ma <jianwei.ma@intel.com>
 Jianwei Mei <jianweix.mei@intel.com>
+Jianyue Wu <jianyue.wu@nokia-sbell.com>
 Jiaqi Min <jiaqix.min@intel.com>
 Jiawei Wang <jiaweiw@nvidia.com> <jiaweiw@mellanox.com>
 Jiawei Zhu <zhujiawei12@huawei.com>
diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e91..56bc7995eb5f 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -5,6 +5,7 @@
 
 #include <errno.h>
 #include <pthread.h>
+#include <sched.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
@@ -114,6 +115,35 @@ thread_start_wrapper(void *arg)
 	return (void *)(uintptr_t)thread_func(thread_args);
 }
 
+/* Function to convert cpu_set_t to a string. */
+static void cpuset_to_string(const cpu_set_t *cpuset,
+			char *cpus_str, size_t cpus_str_size) {
+	int cpu;
+	// Track the current position in the string
+	size_t offset = 0;
+
+	// Clear the string buffer
+	memset(cpus_str, 0, cpus_str_size);
+	cpus_str_size = RTE_MAX_LCORE < cpus_str_size ?
+		RTE_MAX_LCORE : cpus_str_size;
+
+	// Iterate over each CPU core, and check if it is included in the set
+	for (cpu = 0; cpu < RTE_MAX_LCORE && offset < cpus_str_size - 1; ++cpu) {
+		if (CPU_ISSET(cpu, cpuset)) {
+			// Append the current CPU number to the string
+			int written = snprintf(cpus_str + offset, cpus_str_size - offset,
+				"%s%d", (offset > 0 ? "," : ""), cpu);
+			if (written > 0)
+				offset += written;
+			if (offset >= cpus_str_size - 1)
+				break;
+			}
+	}
+
+	// Ensure the string is properly terminated
+	cpus_str[cpus_str_size - 1] = '\0';
+}
+
 int
 rte_thread_create(rte_thread_t *thread_id,
 		const rte_thread_attr_t *thread_attr,
@@ -369,8 +399,25 @@ 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_MAX_LCORE + 1] = {'\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!");
+		cpuset_to_string(cpuset, cpus_str, sizeof(cpus_str));
+		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] 14+ messages in thread

* Re: [PATCH] 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-22 13:49     ` Ferruh Yigit
@ 2024-04-22 13:50     ` Ferruh Yigit
  2024-04-22 15:26     ` Stephen Hemminger
                       ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Ferruh Yigit @ 2024-04-22 13:50 UTC (permalink / raw)
  To: Jianyue Wu (NSB), roretzla, thomas, david.marchand; +Cc: 'dev@dpdk.org'

On 4/22/2024 2:23 PM, Jianyue Wu (NSB) wrote:
> 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.
> 

Thanks Dave, I sent the patch for you, you can follow the CI test
results from patchwork link:
https://patchwork.dpdk.org/project/dpdk/patch/20240422134917.3740545-1-ferruh.yigit@amd.com/


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

* Re: [PATCH] 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-22 13:49     ` Ferruh Yigit
  2024-04-22 13:50     ` Ferruh Yigit
@ 2024-04-22 15:26     ` Stephen Hemminger
  2024-04-22 15:27     ` Stephen Hemminger
                       ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2024-04-22 15:26 UTC (permalink / raw)
  To: Jianyue Wu (NSB); +Cc: roretzla, thomas, david.marchand, 'dev@dpdk.org'

On Mon, 22 Apr 2024 13:23:50 +0000
"Jianyue Wu (NSB)" <jianyue.wu@nokia-sbell.com> wrote:

> +/* Function to convert cpu_set_t to a string. */
> +static void cpuset_to_string(const cpu_set_t *cpuset,
> +			char *cpus_str, size_t cpus_str_size) {
> +	int cpu;
> +	// Track the current position in the string

DPDK does not use C++ style comments.

All patches should match the style of existing code.


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

* Re: [PATCH] eal/linux: enhanced error handling for affinity
  2024-04-22 13:23   ` [PATCH] eal/linux: enhanced error handling for affinity Jianyue Wu (NSB)
                       ` (2 preceding siblings ...)
  2024-04-22 15:26     ` Stephen Hemminger
@ 2024-04-22 15:27     ` Stephen Hemminger
  2024-04-22 15:30     ` Stephen Hemminger
                       ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2024-04-22 15:27 UTC (permalink / raw)
  To: Jianyue Wu (NSB); +Cc: roretzla, thomas, david.marchand, 'dev@dpdk.org'

On Mon, 22 Apr 2024 13:23:50 +0000
"Jianyue Wu (NSB)" <jianyue.wu@nokia-sbell.com> wrote:

> +	char cpus_str[RTE_MAX_LCORE + 1] = {'\0'};
> +	char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'};
> +

You don't need '\0' here, just doing { } will have same effect.

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

* Re: [PATCH] eal/linux: enhanced error handling for affinity
  2024-04-22 13:23   ` [PATCH] eal/linux: enhanced error handling for affinity Jianyue Wu (NSB)
                       ` (3 preceding siblings ...)
  2024-04-22 15:27     ` Stephen Hemminger
@ 2024-04-22 15:30     ` Stephen Hemminger
  2024-04-23  3:01     ` Jianyue Wu (NSB)
  2024-04-24  5:45     ` [PATCH v2] " Jianyue Wu (NSB)
  6 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2024-04-22 15:30 UTC (permalink / raw)
  To: Jianyue Wu (NSB); +Cc: roretzla, thomas, david.marchand, 'dev@dpdk.org'

On Mon, 22 Apr 2024 13:23:50 +0000
"Jianyue Wu (NSB)" <jianyue.wu@nokia-sbell.com> wrote:

> +		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));
> +	}

That error message is way too long, and error strings should not be broken across lines.

			"Set affinity thread %s to %s failed: %s"

And it is a lot effort to deduce the cpuset and thread name here.
Probably better to just move the error message back to the caller.



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

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

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

Hello,

Please disregard this email; I will use a different mailbox instead.

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 #2: Type: text/html, Size: 5029 bytes --]

^ permalink raw reply	[flat|nested] 14+ 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)
                       ` (5 preceding siblings ...)
  2024-04-23  3:01     ` Jianyue Wu (NSB)
@ 2024-04-24  5:45     ` Jianyue Wu (NSB)
  6 siblings, 0 replies; 14+ 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] 14+ messages in thread

* Re: [PATCH] eal/linux: enhanced error handling for affinity
  2024-04-22 13:49     ` Ferruh Yigit
@ 2024-04-26 21:31       ` Patrick Robb
  0 siblings, 0 replies; 14+ messages in thread
From: Patrick Robb @ 2024-04-26 21:31 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: Thomas Monjalon, dev, David Marchand, roretzla, Jianyue Wu

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

Recheck-request: iol-compile-amd64-testing

The DPDK Community Lab updated to the latest Alpine image yesterday, which
resulted in all Alpine builds failing. The failure is unrelated to your
patch, and this recheck should remove the fail on Patchwork, as we have
disabled Alpine testing for now.

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

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

* Re: [PATCH] eal/linux: enhanced error handling for affinity
  2024-04-25  5:40     ` 吴剑跃
@ 2024-04-25 15:04       ` Stephen Hemminger
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2024-04-25 15:04 UTC (permalink / raw)
  To: 吴剑跃; +Cc: dev

On Thu, 25 Apr 2024 13:40:21 +0800 (CST)
吴剑跃 <wujianyue000@163.com> wrote:

> After reviewing the code, I believe that the combination of the __linux__ and _GNU_SOURCE macros effectively confirms whether the pthread_getname_np() API can be utilized. I will proceed with adding them. Thank you~
> #if defined(__linux__) && defined(_GNU_SOURCE)
> 
> 
> 在 2024-04-25 09:08:59,"吴剑跃" <wujianyue000@163.com> 写道:
> 
> Hello, Stephen,
> 
> 
> 
> Good day
> The issue is not caused by DPDK itself, but arises when the DPDK worker process attempts to set affinity to a cpuset that exceeds the limits set by the cgroup cpuset settings.
> Original error prints are:
>      PANIC in rte_eal_init():
>      Cannot set affinity
>      # Callstacks.
> 
> 
> Finding the detailed reason for the failure was challenging, so I added extra print statements to help diagnose the issue.
> I understand your concern about maintaining OS independence with the rte_thread functions. This change aims to provide more context when errors occur, facilitating quicker troubleshooting. I agree that this introduces more code and could be seen as platform-specific. Perhaps we could implement this conditionally, only for platforms where such detailed logging is supported and useful.
> 

My point is that just giving the kernel error should be sufficient, rather than having
to reformat the incoming arguments. The arguments are coming from the command line, and what I
would do is look at the error and the command line arguments to the application, as well as
any kernel logs.

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

* Re: [PATCH] eal/linux: enhanced error handling for affinity
  2024-04-23  3:02 [PATCH] " Jianyue Wu
@ 2024-04-24 15:50 ` Stephen Hemminger
  2024-04-25  1:08   ` 吴剑跃
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Hemminger @ 2024-04-24 15:50 UTC (permalink / raw)
  To: Jianyue Wu; +Cc: dev

On Tue, 23 Apr 2024 11:02:43 +0800
Jianyue Wu <wujianyue000@163.com> wrote:

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

Is this an error you saw in your application or something inside DPDK?

> Changes:
> 1. Check the return value of pthread_setaffinity_np() and log an error
> if the call fails.

Not sure this is necessary. The rte_thread functions are intended to
be os independent wrapper for threads. Does it need to be this chatty.

> 2. Include the current thread name, the intended CPU set, and a detailed
> error message in the log.

This introduces a more code and ends up being Linux/BSD specific only
for the case where application did something wrong.

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

* [PATCH] eal/linux: enhanced error handling for affinity
@ 2024-04-23  3:02 Jianyue Wu
  2024-04-24 15:50 ` Stephen Hemminger
  0 siblings, 1 reply; 14+ messages in thread
From: Jianyue Wu @ 2024-04-23  3:02 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/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] 14+ messages in thread

end of thread, other threads:[~2024-04-26 21:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-22 13:49     ` Ferruh Yigit
2024-04-26 21:31       ` Patrick Robb
2024-04-22 13:50     ` Ferruh Yigit
2024-04-22 15:26     ` Stephen Hemminger
2024-04-22 15:27     ` Stephen Hemminger
2024-04-22 15:30     ` Stephen Hemminger
2024-04-23  3:01     ` Jianyue Wu (NSB)
2024-04-24  5:45     ` [PATCH v2] " Jianyue Wu (NSB)
2024-04-23  3:02 [PATCH] " Jianyue Wu
2024-04-24 15:50 ` Stephen Hemminger
2024-04-25  1:08   ` 吴剑跃
2024-04-25  5:40     ` 吴剑跃
2024-04-25 15:04       ` Stephen Hemminger

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