[5/7] examples/performance-thread: support set thread name

Message ID 1618051221-19962-6-git-send-email-humin29@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series support set thread name |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

humin (Q) April 10, 2021, 10:40 a.m. UTC
  From: Chengwen Feng <fengchengwen@huawei.com>

This patch supports set helloworld thread name which is helpful for
debugging.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 examples/performance-thread/pthread_shim/main.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/examples/performance-thread/pthread_shim/main.c b/examples/performance-thread/pthread_shim/main.c
index 23e3b5e..4ce3622 100644
--- a/examples/performance-thread/pthread_shim/main.c
+++ b/examples/performance-thread/pthread_shim/main.c
@@ -27,6 +27,7 @@ 
 
 #define DEBUG_APP 0
 #define HELLOW_WORLD_MAX_LTHREADS 10
+#define THREAD_NAME_LEN	16
 
 #ifndef __GLIBC__ /* sched_getcpu() is glibc-specific */
 #define sched_getcpu() rte_lcore_id()
@@ -149,6 +150,7 @@  static void *initial_lthread(void *args __rte_unused)
 		 */
 		pthread_attr_t attr;
 		rte_cpuset_t cpuset;
+		char name[THREAD_NAME_LEN];
 
 		CPU_ZERO(&cpuset);
 		CPU_SET(lcore, &cpuset);
@@ -160,6 +162,9 @@  static void *initial_lthread(void *args __rte_unused)
 				helloworld_pthread, (void *) i);
 		if (ret != 0)
 			rte_exit(EXIT_FAILURE, "Cannot create helloworld thread\n");
+
+		snprintf(name, sizeof(name), "helloworld-%u", (uint32_t)i);
+		rte_thread_setname(tid[i], name);
 	}
 
 	/* wait for 1s to allow threads