[dpdk-dev] [PATCH v2] eal: fix compile error for old glibc caused by pthread_setname_np()

Roger B. Melton rmelton at cisco.com
Wed Nov 25 14:51:35 CET 2015



> +/**
> + * 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

Have you thought about a way to set thread name when glibc < 2.12.  I 
also ran into the problem recently and played around with prctl() 
(Linux) to set thread (process) name.  e.g.

    ret = prctl(PR_SET_NAME,<thread_name>,0,0,0);


There are 2 issues I think:

    1) The semantics are different than prthread_setname_np().  With
    pthread_setname_np() a name can be assigned to any thread, with
    prctl() the name is assigned to the active thread.  That would mean
    that rather than rte_eal_init(), rte_eal_intr_init() could not
    assign thread names.  Rather the threads would have to name themselves.

    2) I think BSD lacks prctl(), but some (not all?) BSD
    implementations have setproctitle() to do the same thing.


It might be too late for 2.2, but something to think about for the future.

Regards,
Roger







More information about the dev mailing list