]> git.droids-corp.org - dpdk.git/commitdiff
eal/linux: fix build with glibc < 2.12
authorFerruh Yigit <ferruh.yigit@intel.com>
Wed, 25 Nov 2015 11:13:55 +0000 (11:13 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 25 Nov 2015 13:41:37 +0000 (14:41 +0100)
pthread_setname_np() function added in glibc 2.12, using this function
in older glibc versions cause compile error:
error: implicit declaration of function "pthread_setname_np"

This patch adds "rte_thread_setname" macro and set it according
glibc >= 2.12 check, thread naming disabled for older glibc versions,
glibc versions that support "pthread_setname_np" will keep using this
function.

Fixes: 67b6d3039e9e ("eal: set name to threads")
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
examples/tep_termination/main.c
examples/vhost/main.c
examples/vhost_xen/main.c
lib/librte_eal/common/include/rte_lcore.h
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 2b67e64a4976ef91e1f2d5d0611d2b20aca20035..f97d552a44d94f677e9463092e96baf4bf1bb03a 100644 (file)
@@ -1249,7 +1249,7 @@ main(int argc, char *argv[])
                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);
+               ret = rte_thread_setname(tid, thread_name);
                if (ret != 0)
                        RTE_LOG(ERR, VHOST_CONFIG, "Cannot set print-stats name\n");
        }
index c081b180448a74a4835ebc45758082fe642e0106..9bfda6d4443fea6244ea0a1e51cd0cbb65234cdd 100644 (file)
@@ -3027,7 +3027,7 @@ main(int argc, char *argv[])
 
                /* Set thread_name for aid in debugging.  */
                snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-stats");
-               ret = pthread_setname_np(tid, thread_name);
+               ret = rte_thread_setname(tid, thread_name);
                if (ret != 0)
                        RTE_LOG(ERR, VHOST_CONFIG,
                                "Cannot set print-stats name\n");
index 3fcc138d274d3bc1234ff2e088622685edc6e6b5..ca725f2b3cccd1308674601a618db3439773eee2 100644 (file)
@@ -1510,7 +1510,7 @@ main(int argc, char *argv[])
 
                /* 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);
+               ret = rte_thread_setname(tid, thread_name);
                if (ret != 0)
                        RTE_LOG(ERR, VHOST_CONFIG,
                                "Cannot set print-stats name\n");
index e03264e35fb31a7ed8fc30de05935468a055de22..25460b92fcc1533485b3e1b6f8dc19fa1a18c198 100644 (file)
@@ -247,6 +247,26 @@ int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
  */
 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
 
+/**
+ * Set thread names.
+ *
+ * Macro to wrap `pthread_setname_np()` with a glibc version check.
+ * Only glibc >= 2.12 supports this feature.
+ *
+ * This macro only used for Linux, BSD does direct libc call.
+ * BSD libc version of function is `pthread_set_name_np()`.
+ */
+#if defined(__DOXYGEN__)
+#define rte_thread_setname(...) pthread_setname_np(__VA_ARGS__)
+#endif
+
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+#define rte_thread_setname(...) pthread_setname_np(__VA_ARGS__)
+#else
+#define rte_thread_setname(...) 0
+#endif
+#endif
 
 #ifdef __cplusplus
 }
index 06536f298f67fee035160cc019219a258d22e9ab..635ec363243556ba9840d90cf57474276e44a27c 100644 (file)
@@ -859,7 +859,7 @@ rte_eal_init(int argc, char **argv)
                /* 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,
+               ret = rte_thread_setname(lcore_config[i].thread_id,
                                                thread_name);
                if (ret != 0)
                        RTE_LOG(ERR, EAL,
index 95beb4c7097820a866ef475f6a503c907afb8a02..470d6a1f57f559a92e4b7cdf569004f60f745291 100644 (file)
@@ -887,7 +887,7 @@ rte_eal_intr_init(void)
                /* 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);
+               ret_1 = rte_thread_setname(intr_thread, thread_name);
                if (ret_1 != 0)
                        RTE_LOG(ERR, EAL,
                        "Failed to set thread name for interrupt handling\n");
index 277565d38f274193ce6dfc5dc9c8efb7d6e20572..d9188fdeee4cb6f6ca40bd86b9f874ab2e7831b7 100644 (file)
@@ -394,7 +394,7 @@ pci_vfio_mp_sync_setup(void)
 
        /* 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);
+       ret = rte_thread_setname(socket_thread, thread_name);
        if (ret)
                RTE_LOG(ERR, EAL,
                        "Failed to set thread name for secondary processes!\n");
index e0642dee3ab7d4a6cbd22be253f37d72ed3d09c5..9ceff3301b29733842326e5d9c642fa0e7ed20a8 100644 (file)
@@ -219,7 +219,7 @@ rte_eal_hpet_init(int make_default)
         * 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);
+       ret = rte_thread_setname(msb_inc_thread_id, thread_name);
        if (ret != 0)
                RTE_LOG(ERR, EAL,
                        "ERROR: Cannot set HPET timer thread name!\n");