]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_10] give threads unique names to assist debugging
authorEvan Hunt <each@isc.org>
Fri, 21 Apr 2017 21:00:23 +0000 (14:00 -0700)
committerEvan Hunt <each@isc.org>
Fri, 21 Apr 2017 21:00:23 +0000 (14:00 -0700)
4602. [func] Threads are now set to human-readable
names to assist debugging, when supported by
the OS. [RT #43234]

(cherry picked from commit d26ae7fc0802f67a50f6f01152f356182d47305e)
(cherry picked from commit 8b9c4592ed718c4187971f1104381faf538bf4f7)

15 files changed:
CHANGES
config.h.in
configure
configure.in
doc/arm/notes.xml
lib/isc/nothreads/include/isc/thread.h
lib/isc/nothreads/thread.c
lib/isc/pthreads/include/isc/thread.h
lib/isc/pthreads/thread.c
lib/isc/task.c
lib/isc/timer.c
lib/isc/unix/socket.c
lib/isc/win32/include/isc/thread.h
lib/isc/win32/libisc.def.in
lib/isc/win32/thread.c

diff --git a/CHANGES b/CHANGES
index 3283df5723fda2893442cad6e2adb8bc182fb9a5..e94ce0eca170580aabdf16764180c3ee67f76606 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+4602.  [func]          Threads are now set to human-readable
+                       names to assist debugging, when supported by
+                       the OS. [RT #43234]
+
 4601.  [bug]           Reject incorrect RSA key lengths during key
                        generation and and sign/verify context
                        creation. [RT #45043]
index 9542ed92dd730842f8d8f374d3615af1f9c0accd..bf7f3858938cd5e19f073a5525a5505d797e1591 100644 (file)
@@ -387,6 +387,15 @@ int sigwait(const unsigned int *set, int *sig);
 /* Support for PTHREAD_MUTEX_ADAPTIVE_NP */
 #undef HAVE_PTHREAD_MUTEX_ADAPTIVE_NP
 
+/* Define to 1 if you have the <pthread_np.h> header file. */
+#undef HAVE_PTHREAD_NP_H
+
+/* Define to 1 if you have the `pthread_setname_np' function. */
+#undef HAVE_PTHREAD_SETNAME_NP
+
+/* Define to 1 if you have the `pthread_set_name_np' function. */
+#undef HAVE_PTHREAD_SET_NAME_NP
+
 /* Define to 1 if you have the `pthread_yield' function. */
 #undef HAVE_PTHREAD_YIELD
 
index ad0cc7c9febccd00d9ab35b32a5759d49e033b4b..6a89356c94d3dd97872d22ef220d5932664c4861 100755 (executable)
--- a/configure
+++ b/configure
                        ;;
        esac
 
+       # Look for functions relating to thread naming
+       for ac_func in pthread_setname_np pthread_set_name_np
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+       for ac_header in pthread_np.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "pthread_np.h" "ac_cv_header_pthread_np_h" "$ac_includes_default"
+if test "x$ac_cv_header_pthread_np_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PTHREAD_NP_H 1
+_ACEOF
+
+fi
+
+done
+
+
        #
        # Look for sysconf to allow detection of the number of processors.
        #
index 93e35823278bdff7038f08c7ba2c60183bd7fa63..df08e692cc74e45cc20e5c8be1da731fdb56eea4 100644 (file)
@@ -1344,6 +1344,10 @@ then
                        ;;
        esac
 
+       # Look for functions relating to thread naming
+       AC_CHECK_FUNCS(pthread_setname_np pthread_set_name_np)
+       AC_CHECK_HEADERS(pthread_np.h)
+
        #
        # Look for sysconf to allow detection of the number of processors.
        #
index ec4d94bdd74d9ee1819642cff78aa55f6a544d2b..43136db59162f5b184cfbc854a9c735984eda4d6 100644 (file)
     <itemizedlist>
       <listitem>
        <para>
-         None.
+         Threads in <command>named</command> are now set to human-readable
+         names to assist debugging on operating systems that support that.
+         Threads will have names such as "isc-timer", "isc-sockmgr",
+         "isc-worker0001", and so on. This will affect the reporting of
+         subsidiary thread names in <command>ps</command> and
+         <command>top</command>, but not the main thread. [RT #43234]
        </para>
       </listitem>
     </itemizedlist>
index fee57005b62c803e3d9ca3db95bc3cf672d37674..8aa63172f6f921e941558c49b45490b676f6bc78 100644 (file)
@@ -28,6 +28,9 @@ ISC_LANG_BEGINDECLS
 void
 isc_thread_setconcurrency(unsigned int level);
 
+void
+isc_thread_setname(isc_thread_t, const char *);
+
 #define isc_thread_self() ((unsigned long)0)
 #define isc_thread_yield() ((void)0)
 
index 9075e25513df53085d0c0189318dce4911d244d0..f4f845701a4d6d07b9e7f4459623f7a50ca26f6f 100644 (file)
@@ -26,3 +26,8 @@ void
 isc_thread_setconcurrency(unsigned int level) {
        UNUSED(level);
 }
+
+void isc_thread_setname(isc_thread_t thread, const char *name) {
+       UNUSED(thread);
+       UNUSED(name);
+}
index 47648830e911d259a365cfad891ee2cdf2208230..86473e435b6c3fd328492747a306c8d06470a266 100644 (file)
 
 #include <pthread.h>
 
+#if defined(HAVE_PTHREAD_NP_H)
+#include <pthread_np.h>
+#endif
+
 #include <isc/lang.h>
 #include <isc/result.h>
 
@@ -44,6 +48,9 @@ isc_thread_setconcurrency(unsigned int level);
 void
 isc_thread_yield(void);
 
+void
+isc_thread_setname(isc_thread_t, const char *);
+
 /* XXX We could do fancier error handling... */
 
 #define isc_thread_join(t, rp) \
index 97821a2cadb0499b0dd4532e6d1e57f8ad55b1d7..85e5444234094da1df1e66d4bb52af9e0491ead9 100644 (file)
@@ -79,6 +79,22 @@ isc_thread_setconcurrency(unsigned int level) {
 #endif
 }
 
+void
+isc_thread_setname(isc_thread_t thread, const char *name) {
+#if defined(HAVE_PTHREAD_SETNAME_NP) && defined(_GNU_SOURCE)
+       /*
+        * macOS has pthread_setname_np but only works on the
+        * current thread so it's not used here
+       */
+       (void)pthread_setname_np(thread, name);
+#elif defined(HAVE_PTHREAD_SET_NAME_NP)
+       (void)pthread_set_name_np(thread, name);
+#else
+       UNUSED(thread);
+       UNUSED(name);
+#endif
+}
+
 void
 isc_thread_yield(void) {
 #if defined(HAVE_SCHED_YIELD)
index 44da80c6771e5cd9cccf2fcf2aa5773a477a2f73..9a627c241aea7ffa61270a34919ce1f032d0c2a1 100644 (file)
@@ -1438,6 +1438,10 @@ isc__taskmgr_create(isc_mem_t *mctx, unsigned int workers,
                if (isc_thread_create(run, manager,
                                      &manager->threads[manager->workers]) ==
                    ISC_R_SUCCESS) {
+                       char name[16];  /* thread name limit on Linux */
+                       snprintf(name, sizeof(name), "isc-worker%04d", i);
+                       isc_thread_setname(manager->threads[manager->workers],
+                                          name);
                        manager->workers++;
                        started++;
                }
index 7e6242794a048a99743bfea4047ecafbeebe85bc..7e466d0ac269ed18f675769dc0a2e0c241ecfdc9 100644 (file)
@@ -923,6 +923,7 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
                                                ISC_MSG_FAILED, "failed"));
                return (ISC_R_UNEXPECTED);
        }
+       isc_thread_setname(manager->thread, "isc-timer");
 #endif
 #ifdef USE_SHARED_MANAGER
        manager->refs = 1;
index 3e8c95aecbabebaf1e05c4414323e38967dbbaab..259eef823a1e23ec3484d2837ec6790470667799 100644 (file)
@@ -4755,6 +4755,7 @@ isc__socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
                result = ISC_R_UNEXPECTED;
                goto cleanup;
        }
+       isc_thread_setname(manager->watcher, "isc-socket");
 #endif /* USE_WATCHER_THREAD */
        isc_mem_attach(mctx, &manager->mctx);
 
index bfe860b659f7156ebd2dc2c7c598165dd62e7b63..3de056aa0d3edc60ce8b3ca95ef213af060c03b8 100644 (file)
@@ -83,6 +83,9 @@ isc_thread_join(isc_thread_t, isc_threadresult_t *);
 void
 isc_thread_setconcurrency(unsigned int level);
 
+void
+isc_thread_setname(isc_thread_t, const char *);
+
 int
 isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
 
index ce8567a35795ea9fe0da81995d76e9b4c65cb355..0ff9430cf07c4564765736220f523182feb674ed 100644 (file)
@@ -668,6 +668,7 @@ isc_thread_key_delete
 isc_thread_key_getspecific
 isc_thread_key_setspecific
 isc_thread_setconcurrency
+isc_thread_setname
 isc_time_add
 isc_time_compare
 isc_time_formatISO8601
index be955ea25c21da08fa6c915f08f8278fc7566fe6..7e717ca4a0ee8753adbed13fe841eccdb30d6a8d 100644 (file)
@@ -67,6 +67,12 @@ isc_thread_setconcurrency(unsigned int level) {
         */
 }
 
+void
+isc_thread_setname(isc_thread_t thread, const char *name) {
+       UNUSED(thread);
+       UNUSED(name);
+}
+
 void *
 isc_thread_key_getspecific(isc_thread_key_t key) {
        return(TlsGetValue(key));