]> git.droids-corp.org - dpdk.git/commitdiff
eal: set name to threads
authorRavi Kerur <rkerur@gmail.com>
Wed, 29 Jul 2015 00:51:44 +0000 (17:51 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 3 Nov 2015 14:32:34 +0000 (15:32 +0100)
This patch adds support for pthread_setname_np on Linux and
pthread_set_name_np on FreeBSD.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
[Thomas: add name in tep_termination example]

13 files changed:
examples/tep_termination/Makefile
examples/tep_termination/main.c
examples/vhost/Makefile
examples/vhost/main.c
examples/vhost_xen/Makefile
examples/vhost_xen/main.c
lib/librte_eal/bsdapp/eal/eal.c
lib/librte_eal/common/include/rte_eal.h
lib/librte_eal/linuxapp/eal/Makefile
lib/librte_eal/linuxapp/eal/eal.c
lib/librte_eal/linuxapp/eal/eal_interrupts.c
lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
lib/librte_eal/linuxapp/eal/eal_timer.c

index c37e50f9f0ceb874dd46ca5b8aed17809c69fc66..448e6183220d7d63f16ca977ab5f23546a29fa1f 100644 (file)
@@ -51,5 +51,6 @@ SRCS-y := main.c vxlan_setup.c vxlan.c
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -D_GNU_SOURCE
 
 include $(RTE_SDK)/mk/rte.extapp.mk
index bd776172d301f00aa3756c1dd67ec9eb4366b8ef..2b67e64a4976ef91e1f2d5d0611d2b20aca20035 100644 (file)
@@ -1167,6 +1167,7 @@ main(int argc, char *argv[])
        uint8_t portid;
        uint16_t queue_id;
        static pthread_t tid;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        /* init EAL */
        ret = rte_eal_init(argc, argv);
@@ -1243,8 +1244,15 @@ main(int argc, char *argv[])
        memset(&dev_statistics, 0, sizeof(dev_statistics));
 
        /* Enable stats if the user option is set. */
-       if (enable_stats)
-               pthread_create(&tid, NULL, (void *)print_stats, NULL);
+       if (enable_stats) {
+               ret = pthread_create(&tid, NULL, (void *)print_stats, NULL);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE, "Cannot create print-stats thread\n");
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-stats");
+               ret = pthread_setname_np(tid, thread_name);
+               if (ret != 0)
+                       RTE_LOG(ERR, VHOST_CONFIG, "Cannot set print-stats name\n");
+       }
 
        /* Launch all data cores. */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
index c269466d6740535ca955dd6993aaa01798c80cea..e95c68aebaa19b9ff6bf25d4cbd913644a9ef6f1 100644 (file)
@@ -52,6 +52,7 @@ SRCS-y := main.c
 
 CFLAGS += -O2 -D_FILE_OFFSET_BITS=64
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -D_GNU_SOURCE
 
 include $(RTE_SDK)/mk/rte.extapp.mk
 
index 9eac2d05ee3c2b3e143a05545bc936b74f5f4185..c081b180448a74a4835ebc45758082fe642e0106 100644 (file)
@@ -2896,6 +2896,7 @@ main(int argc, char *argv[])
        uint8_t portid;
        uint16_t queue_id;
        static pthread_t tid;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        signal(SIGINT, sigint_handler);
 
@@ -3018,8 +3019,19 @@ main(int argc, char *argv[])
        memset(&dev_statistics, 0, sizeof(dev_statistics));
 
        /* Enable stats if the user option is set. */
-       if (enable_stats)
-               pthread_create(&tid, NULL, (void*)print_stats, NULL );
+       if (enable_stats) {
+               ret = pthread_create(&tid, NULL, (void *)print_stats, NULL);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Cannot create print-stats thread\n");
+
+               /* Set thread_name for aid in debugging.  */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-stats");
+               ret = pthread_setname_np(tid, thread_name);
+               if (ret != 0)
+                       RTE_LOG(ERR, VHOST_CONFIG,
+                               "Cannot set print-stats name\n");
+       }
 
        /* Launch all data cores. */
        if (zero_copy == 0) {
index e6fa1a1ded67d4f32885ca2b4ff696fd847c695f..47e14898a20f2a8cd51c92bbb4546e45cdf69246 100644 (file)
@@ -46,6 +46,7 @@ SRCS-y := main.c vhost_monitor.c xenstore_parse.c
 
 CFLAGS += -O2 -I/usr/local/include -D_FILE_OFFSET_BITS=64 -Wno-unused-parameter
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -D_GNU_SOURCE
 LDFLAGS += -lxenstore
 
 include $(RTE_SDK)/mk/rte.extapp.mk
index 5d20700031089efe6efc21eb1d1d3aec5f28905f..3fcc138d274d3bc1234ff2e088622685edc6e6b5 100644 (file)
@@ -1432,6 +1432,7 @@ main(int argc, char *argv[])
        int ret;
        uint8_t portid;
        static pthread_t tid;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        /* init EAL */
        ret = rte_eal_init(argc, argv);
@@ -1501,8 +1502,19 @@ main(int argc, char *argv[])
        memset(&dev_statistics, 0, sizeof(dev_statistics));
 
        /* Enable stats if the user option is set. */
-       if (enable_stats)
-               pthread_create(&tid, NULL, (void*)print_stats, NULL );
+       if (enable_stats) {
+               ret = pthread_create(&tid, NULL, (void *)print_stats, NULL);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Cannot create print-stats thread\n");
+
+               /* Set thread_name for aid in debugging. */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-xen-stats");
+               ret = pthread_setname_np(tid, thread_name);
+               if (ret != 0)
+                       RTE_LOG(ERR, VHOST_CONFIG,
+                               "Cannot set print-stats name\n");
+       }
 
        /* Launch all data cores. */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
index 1b6f705c0453f807f97211f27ee4da045b651414..e8cc4ac78d5f7be25be10c760e86abefbc4aa0f2 100644 (file)
@@ -467,6 +467,7 @@ rte_eal_init(int argc, char **argv)
        pthread_t thread_id;
        static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
        char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        if (!rte_atomic32_test_and_set(&run_once))
                return -1;
@@ -572,6 +573,11 @@ rte_eal_init(int argc, char **argv)
                                     eal_thread_loop, NULL);
                if (ret != 0)
                        rte_panic("Cannot create thread\n");
+
+               /* Set thread_name for aid in debugging. */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
+                               "lcore-slave-%d", i);
+               pthread_set_name_np(lcore_config[i].thread_id, thread_name);
        }
 
        /*
index f36a792f6ac626fdbcba1a624a77ffa5d4abaf20..d2816a84ab84103727096f18c8dd028a812106d9 100644 (file)
@@ -51,6 +51,9 @@ extern "C" {
 
 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
 
+/* Maximum thread_name length. */
+#define RTE_MAX_THREAD_NAME_LEN 16
+
 /**
  * The lcore role (used in RTE or not).
  */
index d62196e5d71767dac60cd575b95cfce4c543664c..7e36b86e53806bcd083aac2f0214b29934f3cac5 100644 (file)
@@ -93,6 +93,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += malloc_heap.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
+CFLAGS_eal_pci_vfio_mp_sync.o := -D_GNU_SOURCE
+CFLAGS_eal_timer.o := -D_GNU_SOURCE
 CFLAGS_eal_lcore.o := -D_GNU_SOURCE
 CFLAGS_eal_thread.o := -D_GNU_SOURCE
 CFLAGS_eal_log.o := -D_GNU_SOURCE
index e0ad1d76b7c741573a1e8a5cf86e384c3d65a8e4..d70d8f87d51461dd23fa5a71c7ef9175107df4c5 100644 (file)
@@ -734,6 +734,7 @@ rte_eal_init(int argc, char **argv)
        struct shared_driver *solib = NULL;
        const char *logid;
        char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        if (!rte_atomic32_test_and_set(&run_once))
                return -1;
@@ -863,6 +864,15 @@ rte_eal_init(int argc, char **argv)
                                     eal_thread_loop, NULL);
                if (ret != 0)
                        rte_panic("Cannot create thread\n");
+
+               /* Set thread_name for aid in debugging. */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
+                       "lcore-slave-%d", i);
+               ret = pthread_setname_np(lcore_config[i].thread_id,
+                                               thread_name);
+               if (ret != 0)
+                       RTE_LOG(ERR, EAL,
+                               "Cannot set name for lcore thread\n");
        }
 
        /*
index 79eedafc6345fdca2a35604b3cdd706876de1c8a..a4b9506a9cd7a864de5b91ac8f58bebcd7a495af 100644 (file)
@@ -67,6 +67,7 @@
 
 #include "eal_private.h"
 #include "eal_vfio.h"
+#include "eal_thread.h"
 
 #define EAL_INTR_EPOLL_WAIT_FOREVER (-1)
 #define NB_OTHER_INTR               1
@@ -860,7 +861,8 @@ eal_intr_thread_main(__rte_unused void *arg)
 int
 rte_eal_intr_init(void)
 {
-       int ret = 0;
+       int ret = 0, ret_1 = 0;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        /* init the global interrupt source head */
        TAILQ_INIT(&intr_sources);
@@ -875,9 +877,18 @@ rte_eal_intr_init(void)
        /* create the host thread to wait/handle the interrupt */
        ret = pthread_create(&intr_thread, NULL,
                        eal_intr_thread_main, NULL);
-       if (ret != 0)
+       if (ret != 0) {
                RTE_LOG(ERR, EAL,
                        "Failed to create thread for interrupt handling\n");
+       } else {
+               /* Set thread_name for aid in debugging. */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
+                       "eal-intr-thread");
+               ret_1 = pthread_setname_np(intr_thread, thread_name);
+               if (ret_1 != 0)
+                       RTE_LOG(ERR, EAL,
+                       "Failed to set thread name for interrupt handling\n");
+       }
 
        return -ret;
 }
index fec7080504ed24e2a5f2d4356afaebc71d5ca48d..277565d38f274193ce6dfc5dc9c8efb7d6e20572 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/socket.h>
+#include <pthread.h>
 
 /* sys/un.h with __USE_MISC uses strlen, which is unsafe */
 #ifdef __USE_MISC
@@ -54,6 +55,7 @@
 
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
+#include "eal_thread.h"
 
 /**
  * @file
@@ -374,6 +376,7 @@ int
 pci_vfio_mp_sync_setup(void)
 {
        int ret;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        if (vfio_mp_sync_socket_setup() < 0) {
                RTE_LOG(ERR, EAL, "Failed to set up local socket!\n");
@@ -383,11 +386,19 @@ pci_vfio_mp_sync_setup(void)
        ret = pthread_create(&socket_thread, NULL,
                        pci_vfio_mp_sync_thread, NULL);
        if (ret) {
-               RTE_LOG(ERR, EAL, "Failed to create thread for communication with "
-                               "secondary processes!\n");
+               RTE_LOG(ERR, EAL,
+                       "Failed to create thread for communication with secondary processes!\n");
                close(mp_socket_fd);
                return -1;
        }
+
+       /* Set thread_name for aid in debugging. */
+       snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "pci-vfio-sync");
+       ret = pthread_setname_np(socket_thread, thread_name);
+       if (ret)
+               RTE_LOG(ERR, EAL,
+                       "Failed to set thread name for secondary processes!\n");
+
        return 0;
 }
 
index 76a8a651d87fe1dcedb3172ba2f8cd3b36fc517d..e0642dee3ab7d4a6cbd22be253f37d72ed3d09c5 100644 (file)
@@ -166,6 +166,7 @@ int
 rte_eal_hpet_init(int make_default)
 {
        int fd, ret;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        if (internal_config.no_hpet) {
                RTE_LOG(NOTICE, EAL, "HPET is disabled\n");
@@ -208,12 +209,21 @@ rte_eal_hpet_init(int make_default)
         * msb (hpet is 32 bits by default under linux) */
        ret = pthread_create(&msb_inc_thread_id, NULL,
                        (void *(*)(void *))hpet_msb_inc, NULL);
-       if (ret < 0) {
+       if (ret != 0) {
                RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n");
                internal_config.no_hpet = 1;
                return -1;
        }
 
+       /*
+        * Set thread_name for aid in debugging.
+        */
+       snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "hpet-msb-inc");
+       ret = pthread_setname_np(msb_inc_thread_id, thread_name);
+       if (ret != 0)
+               RTE_LOG(ERR, EAL,
+                       "ERROR: Cannot set HPET timer thread name!\n");
+
        if (make_default)
                eal_timer_source = EAL_TIMER_HPET;
        return 0;