pthreaded servers: set thread names
authorGarrett Wollman <wollman@csail.mit.edu>
Mon, 18 Jul 2011 01:57:20 +0000 (21:57 -0400)
committerDerrick Brashear <shadow@dementia.org>
Fri, 29 Jul 2011 21:16:25 +0000 (14:16 -0700)
In the startup function for each thread, set a thread name.  This
can safely be done unconditionally as LWP builds turn the call into
a no-op.  In general, the thread name parallels the name passed to
LWP_CreateProcess, but for Rx server threads, it additionally includes
the thread ID so that these threads can easily be distinguished.  (I'm
not sure yet whether doing so will prove to be useful or counterproductive.)

Change-Id: I30e012eebef4c7856084fa8b8eb1d88d9fcdf2c4
Reviewed-on: http://gerrit.openafs.org/5041
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

17 files changed:
src/budb/dbs_dump.c
src/butc/dbentries.c
src/butc/dump.c
src/butc/lwps.c
src/butc/recoverDb.c
src/butc/tcudbprocs.c
src/tptserver/Makefile.in
src/tubik/Makefile.in
src/tviced/Makefile.in
src/tvlserver/Makefile.in
src/tvolser/Makefile.in
src/ubik/beacon.c
src/ubik/recovery.c
src/viced/viced.c
src/vol/fssync-server.c
src/vol/ihandle.c
src/volser/volmain.c

index f1dc0b3..26921a9 100644 (file)
@@ -21,6 +21,7 @@
 #include <rx/rxkad.h>
 #include <afs/cellconfig.h>
 #include <afs/audit.h>
+#include <afs/afsutil.h>
 
 #include "budb.h"
 #include "budb_errs.h"
@@ -56,6 +57,7 @@ setupDbDump(void *param)
     int writeFid = (intptr_t)param;
     afs_int32 code = 0;
 
+    afs_pthread_setname_self("Database Dumper");
     code = InitRPC(&dumpSyncPtr->ut, LOCKREAD, 1);
     if (code)
        goto error_exit;
@@ -315,6 +317,7 @@ dumpWatcher(void *unused)
 {
     afs_int32 code;
 
+    afs_pthread_setname_self("Database Dump Watchdog");
     while (1) {                        /*w */
 
        /* printf("dumpWatcher\n"); */
index be9b343..5efc3ac 100644 (file)
@@ -327,6 +327,7 @@ dbWatcher(void *unused)
     afs_int32 code = 0;
     int i, c, addedDump;
 
+    afs_pthread_setname_self("dbWatcher");
     dlqInit(&entries_to_flush);
     dlqInit(&savedEntries);
 
index 532324f..2d95e09 100644 (file)
@@ -1128,6 +1128,7 @@ Dumper(void *param)
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
 
+    afs_pthread_setname_self("dumper");
     taskId = nodePtr->taskID;  /* Get task Id */
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -2029,6 +2030,7 @@ DeleteDump(void *param)
     extern struct udbHandleS udbHandle;
     extern struct deviceSyncNode *deviceLatch;
 
+    afs_pthread_setname_self("deletedump");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
     clearStatus(taskId, DRIVE_WAIT);
index 47bc3fa..1d80c9b 100644 (file)
@@ -1638,6 +1638,7 @@ Restorer(void *param) {
     time_t startTime, endTime;
     afs_int32 goodrestore = 0;
 
+    afs_pthread_setname_self("restorer");
     taskId = newNode->taskID;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -2104,6 +2105,7 @@ Labeller(void *param)
     afs_uint32 taskId;
     afs_int32 code = 0;
 
+    afs_pthread_setname_self("labeller");
     taskId = labelIfPtr->taskId;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
index 4081316..8b60945 100644 (file)
@@ -16,6 +16,7 @@
 #include <rx/rx.h>
 #include <lwp.h>
 #include <lock.h>
+#include <afs/afsutil.h>
 #include <afs/tcdata.h>
 #include <afs/bubasics.h>
 #include <afs/budb.h>
@@ -705,6 +706,7 @@ ScanDumps(void *param)
     afs_uint32 taskId;
     afs_int32 code = 0;
 
+    afs_pthread_setname_self("scandump");
     taskId = ptr->taskId;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
index 450f4d5..296652c 100644 (file)
@@ -640,6 +640,7 @@ saveDbToTape(void *param)
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
 
+    afs_pthread_setname_self("Db save");
     expires = (saveDbIfPtr->archiveTime ? NEVERDATE : 0);
     taskId = saveDbIfPtr->taskId;
 
@@ -1022,6 +1023,7 @@ restoreDbFromTape(void *param)
     extern struct tapeConfig globalTapeConfig;
     extern struct deviceSyncNode *deviceLatch;
 
+    afs_pthread_setname_self("Db restore");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);     /* lock tape device */
     clearStatus(taskId, DRIVE_WAIT);
@@ -1119,6 +1121,7 @@ KeepAlive(void *unused)
 
     extern struct udbHandleS udbHandle;
 
+    afs_pthread_setname_self("Keep-alive");
     while (1) {
 #ifdef AFS_PTHREAD_ENV
        sleep(5);
index 3ac5035..8fe341f 100644 (file)
@@ -19,7 +19,8 @@ PTSERVER=$(srcdir)/../ptserver
 RXOBJS= rx_pthread.o rxkad_errs.o
 
 UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
-     volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o
+     volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \
+     pthread_threadname.o
 
 INCLS=${TOP_INCDIR}/ubik.h \
        ${TOP_INCDIR}/lock.h  \
@@ -94,6 +95,9 @@ hostparse.o: ${UTIL}/hostparse.c
 pthread_glock.o: ${UTIL}/pthread_glock.c
        $(AFS_CCRULE) $(UTIL)/pthread_glock.c
 
+pthread_threadname.o: ${UTIL}/pthread_threadname.c
+       $(AFS_CCRULE) $(UTIL)/pthread_threadname.c
+
 ptserver.o: ${PTSERVER}/ptserver.c ${INCLS}
        $(AFS_CCRULE) $(PTSERVER)/ptserver.c
 
index b4ca2cf..91ed150 100644 (file)
@@ -27,7 +27,8 @@ INCLS=${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/lock.h \
 RXOBJS = rx_pthread.o
 
 UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
-       volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o
+       volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \
+       pthread_threadname.o
 
 LIBS=${RXOBJS} ${UTILOBJS} ${TOP_LIBDIR}/libafsauthent.a ${TOP_LIBDIR}/libafsrpc.a \
      ${TOP_LIBDIR}/libafscom_err.a ${TOP_LIBDIR}/libcmd.a \
@@ -87,6 +88,9 @@ hostparse.o: ${UTIL}/hostparse.c
 pthread_glock.o: ${UTIL}/pthread_glock.c
        $(AFS_CCRULE) $(UTIL)/pthread_glock.c
 
+pthread_threadname.o: ${UTIL}/pthread_threadname.c
+       $(AFS_CCRULE) $(UTIL)/pthread_threadname.c
+
 #
 # insert comments here
 #
index fcd2057..8755220 100644 (file)
@@ -33,7 +33,7 @@ LWPOBJS=lock.o threadname.o
 
 LIBACLOBJS=aclprocs.o netprocs.o
 
-UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o
+UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o pthread_threadname.o
 
 DIROBJS=buffer.o dir.o salvage.o
 
@@ -103,6 +103,9 @@ dirpath.o: ${UTIL}/dirpath.c
 softsig.o: ${UTIL}/softsig.c
        $(AFS_CCRULE) $(UTIL)/softsig.c
 
+pthread_threadname.o: ${UTIL}/pthread_threadname.c
+       $(AFS_CCRULE) $(UTIL)/pthread_threadname.c
+
 lock.o: ${LWP}/lock.c
        $(AFS_CCRULE) $(LWP)/lock.c
 
index 3ba9acb..9975d39 100644 (file)
@@ -20,7 +20,7 @@ RXOBJS= rx_pthread.o rxkad_errs.o
 
 UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
      volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \
-     get_krbrlm.o
+     pthread_threadname.o get_krbrlm.o
 
 INCLS=${TOP_INCDIR}/ubik.h \
              ${TOP_INCDIR}/lwp.h \
@@ -91,6 +91,9 @@ hostparse.o: ${UTIL}/hostparse.c
 pthread_glock.o: ${UTIL}/pthread_glock.c
        $(AFS_CCRULE) $(UTIL)/pthread_glock.c
 
+pthread_threadname.o: ${UTIL}/pthread_threadname.c
+       $(AFS_CCRULE) $(UTIL)/pthread_threadname.c
+
 get_krbrlm.o: ${UTIL}/get_krbrlm.c
        $(AFS_CCRULE) $(UTIL)/get_krbrlm.c
 
index 3506f06..5bdfee6 100644 (file)
@@ -33,7 +33,7 @@ LWPOBJS=lock.o threadname.o
 
 LIBACLOBJS=aclprocs.o netprocs.o
 
-UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o
+UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o pthread_threadname.o
 
 DIROBJS=buffer.o dir.o salvage.o
 
@@ -127,6 +127,9 @@ dirpath.o: ${UTIL}/dirpath.c
 softsig.o: ${UTIL}/softsig.c
        $(AFS_CCRULE) $(UTIL)/softsig.c
 
+pthread_threadname.o: ${UTIL}/pthread_threadname.c
+       $(AFS_CCRULE) $(UTIL)/pthread_threadname.c
+
 lock.o: ${LWP}/lock.c
        $(AFS_CCRULE) $(LWP)/lock.c
 
index eb2d526..d12274d 100644 (file)
@@ -402,6 +402,8 @@ ubeacon_Interact(void *dummy)
     struct ubik_version tversion;
     afs_int32 startTime;
 
+    afs_pthread_setname_self("beacon");
+
     /* loop forever getting votes */
     lastWakeupTime = 0;                /* keep track of time we last started a vote collection */
     while (1) {
index 6c3a8cb..c858728 100644 (file)
@@ -458,6 +458,8 @@ urecovery_Interact(void *dummy)
     int fd = -1;
     afs_int32 pass;
 
+    afs_pthread_setname_self("recovery");
+
     /* otherwise, begin interaction */
     urecovery_state = 0;
     lastProbeTime = 0;
index eef02ca..6cc25ab 100644 (file)
@@ -752,6 +752,7 @@ CheckSignal(void *unused)
 static void *
 ShutdownWatchdogLWP(void *unused)
 {
+    afs_pthread_setname_self("ShutdownWatchdog");
     sleep(panic_timeout);
     ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
                          "within %d seconds; forcing panic\n",
index 25f60c3..f6e9c2f 100644 (file)
@@ -257,6 +257,7 @@ FSYNC_sync(void * args)
     /* set our 'thread-id' so that the host hold table works */
     tid = rx_SetThreadNum();
     Log("Set thread id %d for FSYNC_sync\n", tid);
+    afs_pthread_setname_self("FSYNC_sync");
 #endif /* AFS_PTHREAD_ENV */
 
     VOL_LOCK;
index 892853c..0809aef 100644 (file)
@@ -25,6 +25,7 @@
 #include <rx/xdr.h>
 #include <afs/afsint.h>
 #include <afs/afssyscalls.h>
+#include <afs/afsutil.h>
 
 #include "nfs.h"
 #include "ihandle.h"
@@ -988,6 +989,7 @@ ih_sync_all(void) {
 
 void *
 ih_sync_thread(void *dummy) {
+    afs_pthread_setname_self("ih_syncer");
     while(1) {
 
 #ifdef AFS_PTHREAD_ENV
index daf5920..800f330 100644 (file)
@@ -122,6 +122,7 @@ BKGLoop(void *unused)
     struct timeval tv;
     int loop = 0;
 
+    afs_pthread_setname_self("vol bkg");
     while (1) {
        tv.tv_sec = GCWAKEUP;
        tv.tv_usec = 0;