trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r1103590 - in /trafficserver/traffic/trunk: ./ iocore/aio/ iocore/cluster/ iocore/dns/ iocore/eventsystem/ iocore/net/ lib/records/ lib/ts/ proxy/ proxy/http/remap/ proxy/logging/
Date Mon, 16 May 2011 01:33:44 GMT
Author: zwoop
Date: Mon May 16 01:33:43 2011
New Revision: 1103590

URL: http://svn.apache.org/viewvc?rev=1103590&view=rev
Log:
TS-779 Set thread name for various event types

Modified:
    trafficserver/traffic/trunk/configure.ac
    trafficserver/traffic/trunk/iocore/aio/AIO.cc
    trafficserver/traffic/trunk/iocore/cluster/ClusterProcessor.cc
    trafficserver/traffic/trunk/iocore/dns/DNS.cc
    trafficserver/traffic/trunk/iocore/eventsystem/I_EventProcessor.h
    trafficserver/traffic/trunk/iocore/eventsystem/I_Thread.h
    trafficserver/traffic/trunk/iocore/eventsystem/Tasks.cc
    trafficserver/traffic/trunk/iocore/eventsystem/Thread.cc
    trafficserver/traffic/trunk/iocore/eventsystem/UnixEventProcessor.cc
    trafficserver/traffic/trunk/iocore/net/SSLUnixNet.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc
    trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc
    trafficserver/traffic/trunk/lib/records/RecProcess.cc
    trafficserver/traffic/trunk/lib/ts/ink_platform.h
    trafficserver/traffic/trunk/lib/ts/ink_thread.h
    trafficserver/traffic/trunk/proxy/Main.cc
    trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
    trafficserver/traffic/trunk/proxy/logging/Log.cc

Modified: trafficserver/traffic/trunk/configure.ac
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/configure.ac?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/configure.ac (original)
+++ trafficserver/traffic/trunk/configure.ac Mon May 16 01:33:43 2011
@@ -936,6 +936,7 @@ TS_FLAG_HEADERS([sys/epoll.h \
                   sys/ioctl.h \
                   sys/byteorder.h \
                   sys/sockio.h \
+		  sys/prctl.h \
                   arpa/inet.h \
                   arpa/nameser.h \
                   arpa/nameser_compat.h \

Modified: trafficserver/traffic/trunk/iocore/aio/AIO.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/aio/AIO.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/aio/AIO.cc (original)
+++ trafficserver/traffic/trunk/iocore/aio/AIO.cc Mon May 16 01:33:43 2011
@@ -212,8 +212,10 @@ struct AIOThreadInfo:public Continuation
 static AIO_Reqs *
 aio_init_fildes(int fildes, int fromAPI = 0)
 {
+  char thr_name[MAX_THREAD_NAME_LENGTH];
   int i;
   AIO_Reqs *request = (AIO_Reqs *) malloc(sizeof(AIO_Reqs));
+
   memset(request, 0, sizeof(AIO_Reqs));
 
   INK_WRITE_MEMORY_BARRIER;
@@ -244,7 +246,8 @@ aio_init_fildes(int fildes, int fromAPI 
       thr_info = new AIOThreadInfo(request, 1);
     else
       thr_info = new AIOThreadInfo(request, 0);
-    ink_assert(eventProcessor.spawn_thread(thr_info));
+    snprintf(thr_name, MAX_THREAD_NAME_LENGTH, "[ET_AIO %d]", i);
+    ink_assert(eventProcessor.spawn_thread(thr_info, thr_name));
   }
 
   /* the num_filedes should be incremented after initializing everything.

Modified: trafficserver/traffic/trunk/iocore/cluster/ClusterProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cluster/ClusterProcessor.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cluster/ClusterProcessor.cc (original)
+++ trafficserver/traffic/trunk/iocore/cluster/ClusterProcessor.cc Mon May 16 01:33:43 2011
@@ -723,7 +723,7 @@ ClusterProcessor::start()
 #endif
   if (cache_clustering_enabled && (cacheProcessor.IsCacheEnabled() == CACHE_INITIALIZED))
{
 
-    ET_CLUSTER = eventProcessor.spawn_event_threads(1);
+    ET_CLUSTER = eventProcessor.spawn_event_threads(1, "ET_CLUSTER");
     for (int i = 0; i < eventProcessor.n_threads_for_type[ET_CLUSTER]; i++) {
       initialize_thread_for_net(eventProcessor.eventthread[ET_CLUSTER][i], i);
     }

Modified: trafficserver/traffic/trunk/iocore/dns/DNS.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/DNS.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/DNS.cc (original)
+++ trafficserver/traffic/trunk/iocore/dns/DNS.cc Mon May 16 01:33:43 2011
@@ -119,7 +119,7 @@ DNSProcessor::start(int) {
   IOCORE_EstablishStaticConfigInt32(dns_thread, "proxy.config.dns.dedicated_thread");
 
   if (dns_thread > 0) {
-    ET_DNS = eventProcessor.spawn_event_threads(1); // TODO: Hmmm, should we just get a single
thread some other way?
+    ET_DNS = eventProcessor.spawn_event_threads(1, "ET_DNS"); // TODO: Hmmm, should we just
get a single thread some other way?
     initialize_thread_for_net(eventProcessor.eventthread[ET_DNS][0], 0);
   } else {
     // Initialize the first event thread for DNS.

Modified: trafficserver/traffic/trunk/iocore/eventsystem/I_EventProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/I_EventProcessor.h?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/I_EventProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/I_EventProcessor.h Mon May 16 01:33:43
2011
@@ -103,7 +103,7 @@ public:
     @return event object representing the start of the thread.
 
   */
-  Event * spawn_thread(Continuation * cont, ink_sem * sem = NULL);
+  Event *spawn_thread(Continuation * cont, const char *thr_name, ink_sem * sem = NULL);
 
   /**
     Spawns a group of threads for an event type. Spawns the number of
@@ -114,7 +114,7 @@ public:
     @return EventType or thread id for the new group of threads.
 
   */
-  EventType spawn_event_threads(int n_threads);
+  EventType spawn_event_threads(int n_threads, const char* et_name);
 
 
   /**

Modified: trafficserver/traffic/trunk/iocore/eventsystem/I_Thread.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/I_Thread.h?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/I_Thread.h (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/I_Thread.h Mon May 16 01:33:43 2011
@@ -73,6 +73,8 @@ typedef THREADAPI_RETURN_TYPE(THREADAPI 
 
 extern ProxyMutex *global_mutex;
 
+static const int MAX_THREAD_NAME_LENGTH  = 16;
+
 /**
   Base class for the threads in the Event System. Thread is the base
   class for all the thread classes in the Event System. Objects of the
@@ -127,7 +129,7 @@ private:
   Thread & operator =(const Thread &);
 
 public:
-  void start(ThreadFunction f = NULL, void *a = NULL, size_t stacksize = 0);
+  void start(const char* name, ThreadFunction f = NULL, void *a = NULL, size_t stacksize
= 0);
 
   virtual void execute()
   {  }

Modified: trafficserver/traffic/trunk/iocore/eventsystem/Tasks.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/Tasks.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/Tasks.cc (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/Tasks.cc Mon May 16 01:33:43 2011
@@ -31,6 +31,6 @@ int
 TasksProcessor::start(int task_threads)
 {
   if (task_threads > 0)
-    ET_TASK = eventProcessor.spawn_event_threads(task_threads);
+    ET_TASK = eventProcessor.spawn_event_threads(task_threads, "ET_TASK");
   return 0;
 }

Modified: trafficserver/traffic/trunk/iocore/eventsystem/Thread.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/Thread.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/Thread.cc (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/Thread.cc Mon May 16 01:33:43 2011
@@ -72,13 +72,16 @@ struct thread_data_internal
   ThreadFunction f;
   void *a;
   Thread *me;
+  char name[MAX_THREAD_NAME_LENGTH];
 };
 
 static void *
 spawn_thread_internal(void *a)
 {
   thread_data_internal *p = (thread_data_internal *) a;
+
   p->me->set_specific();
+  ink_set_thread_name(p->name);
   if (p->f)
     p->f(p->a);
   else
@@ -88,14 +91,17 @@ spawn_thread_internal(void *a)
 }
 
 void
-Thread::start(ThreadFunction f, void *a, size_t stacksize)
+Thread::start(const char* name, ThreadFunction f, void *a, size_t stacksize)
 {
-  if (0 == stacksize) {
-    REC_ReadConfigInteger(stacksize, "proxy.config.thread.default.stacksize");
-  }
   thread_data_internal *p = (thread_data_internal *) xmalloc(sizeof(thread_data_internal));
+
+  if (0 == stacksize)
+    REC_ReadConfigInteger(stacksize, "proxy.config.thread.default.stacksize");
+
   p->f = f;
   p->a = a;
   p->me = this;
+  memset(p->name, 0, MAX_THREAD_NAME_LENGTH);
+  ink_strncpy(p->name, name, MAX_THREAD_NAME_LENGTH - 1);
   this->tid = ink_thread_create(spawn_thread_internal, (void *) p, 0, stacksize);
 }

Modified: trafficserver/traffic/trunk/iocore/eventsystem/UnixEventProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/UnixEventProcessor.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/UnixEventProcessor.cc (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/UnixEventProcessor.cc Mon May 16 01:33:43
2011
@@ -26,8 +26,9 @@
 
 
 EventType
-EventProcessor::spawn_event_threads(int n_threads)
+EventProcessor::spawn_event_threads(int n_threads, const char* et_name)
 {
+  char thr_name[MAX_THREAD_NAME_LENGTH];
   EventType new_thread_group_id;
   int i;
 
@@ -45,8 +46,10 @@ EventProcessor::spawn_event_threads(int 
   }
 
   n_threads_for_type[new_thread_group_id] = n_threads;
-  for (i = 0; i < n_threads; i++)
-    eventthread[new_thread_group_id][i]->start();
+  for (i = 0; i < n_threads; i++) {
+    snprintf(thr_name, MAX_THREAD_NAME_LENGTH, "[%s %d]", et_name, i);
+    eventthread[new_thread_group_id][i]->start(thr_name);
+  }
 
   n_thread_groups++;
   n_ethreads += n_threads;
@@ -63,6 +66,7 @@ class EventProcessor eventProcessor;
 int
 EventProcessor::start(int n_event_threads)
 {
+  char thr_name[MAX_THREAD_NAME_LENGTH];
   int i;
 
   // do some sanity checking.
@@ -89,8 +93,10 @@ EventProcessor::start(int n_event_thread
     t->set_event_type((EventType) ET_CALL);
   }
   n_threads_for_type[ET_CALL] = n_event_threads;
-  for (i = first_thread; i < n_ethreads; i++)
-    all_ethreads[i]->start();
+  for (i = first_thread; i < n_ethreads; i++) {
+    snprintf(thr_name, MAX_THREAD_NAME_LENGTH, "[ET_NET %d]", i);
+    all_ethreads[i]->start(thr_name);
+  }
 
   return 0;
 }
@@ -101,14 +107,16 @@ EventProcessor::shutdown()
 }
 
 Event *
-EventProcessor::spawn_thread(Continuation * cont, ink_sem * sem)
+EventProcessor::spawn_thread(Continuation *cont, const char* thr_name, ink_sem *sem)
 {
   Event *e = eventAllocator.alloc();
+
   e->init(cont, 0, 0);
   dthreads[n_dthreads] = NEW(new EThread(DEDICATED, e, sem));
   e->ethread = dthreads[n_dthreads];
   e->mutex = e->continuation->mutex = dthreads[n_dthreads]->mutex;
   n_dthreads++;
-  e->ethread->start();
+  e->ethread->start(thr_name);
+
   return e;
 }

Modified: trafficserver/traffic/trunk/iocore/net/SSLUnixNet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/SSLUnixNet.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/SSLUnixNet.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/SSLUnixNet.cc Mon May 16 01:33:43 2011
@@ -58,7 +58,7 @@ SSLNetProcessor::start(int number_of_ssl
   if (number_of_ssl_threads < 1)
     return -1;
 
-  ET_SSL = eventProcessor.spawn_event_threads(number_of_ssl_threads);
+  ET_SSL = eventProcessor.spawn_event_threads(number_of_ssl_threads, "ET_SSL");
   if (err == 0)
     err = UnixNetProcessor::start();
   return err;

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc Mon May 16 01:33:43 2011
@@ -204,7 +204,7 @@ NetAccept::init_accept_loop()
     action_->mutex = action_->continuation->mutex;
   }
   SET_CONTINUATION_HANDLER(this, &NetAccept::acceptLoopEvent);
-  eventProcessor.spawn_thread(this);
+  eventProcessor.spawn_thread(this, "ts[ACCEPT]");
 }
 
 

Modified: trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc Mon May 16 01:33:43 2011
@@ -106,7 +106,7 @@ UDPNetProcessorInternal::start(int n_upd
   if (n_upd_threads < 1)
     return -1;
 
-  ET_UDP = eventProcessor.spawn_event_threads(n_upd_threads);
+  ET_UDP = eventProcessor.spawn_event_threads(n_upd_threads, "ET_UDP");
   if (ET_UDP < 0)               // Probably can't happen, maybe at some point EventType
should be unsigned ?
     return -1;
 

Modified: trafficserver/traffic/trunk/lib/records/RecProcess.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/records/RecProcess.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/records/RecProcess.cc (original)
+++ trafficserver/traffic/trunk/lib/records/RecProcess.cc Mon May 16 01:33:43 2011
@@ -365,15 +365,15 @@ RecProcessStart()
   Debug("statsproc", "Starting sync processors:");
   raw_stat_sync_cont *rssc = NEW(new raw_stat_sync_cont(new_ProxyMutex()));
   Debug("statsproc", "\traw-stat syncer");
-  eventProcessor.spawn_thread(rssc);
+  eventProcessor.spawn_thread(rssc, "[STAT_SYNC]");
 
   config_update_cont *cuc = NEW(new config_update_cont(new_ProxyMutex()));
   Debug("statsproc", "\tconfig syncer");
-  eventProcessor.spawn_thread(cuc);
+  eventProcessor.spawn_thread(cuc, "[CONF_SYNC]");
 
   sync_cont *sc = NEW(new sync_cont(new_ProxyMutex()));
   Debug("statsproc", "\tremote syncer");
-  eventProcessor.spawn_thread(sc);
+  eventProcessor.spawn_thread(sc, "[REM_SYNC]");
 
   g_started = true;
 

Modified: trafficserver/traffic/trunk/lib/ts/ink_platform.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_platform.h?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_platform.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_platform.h Mon May 16 01:33:43 2011
@@ -204,6 +204,11 @@ typedef unsigned int in_addr_t;
 # include <sys/sysmacros.h>
 #endif
 
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
+
 #ifndef PATH_NAME_MAX
 #define PATH_NAME_MAX 511 // instead of PATH_MAX which is inconsistent
                           // on various OSs (linux-4096,osx/bsd-1024,

Modified: trafficserver/traffic/trunk/lib/ts/ink_thread.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_thread.h?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_thread.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_thread.h Mon May 16 01:33:43 2011
@@ -73,7 +73,6 @@ typedef timestruc_t ink_timestruc;
 //      The POSIX threads interface
 //
 //////////////////////////////////////////////////////////////////////////////
-
 #if defined(POSIX_THREAD)
 
 static inline void
@@ -312,6 +311,17 @@ ink_create_pipe( int pfd[2])
 }
 #endif
 
+// This define is from Linux's <sys/prctl.h> and is most likely very
+// Linux specific... Feel free to add support for other platforms
+// that has a feature to give a thread specific name / tag.
+static inline void
+ink_set_thread_name(const char* name)
+{
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
+  prctl(PR_SET_NAME, name, 0, 0, 0);
+#endif /* no prctl.h and PR_SET_NAME not supported */
+}
+
 #endif /* #if defined(POSIX_THREAD) */
 
 #endif /*_INK_THREAD_H*/

Modified: trafficserver/traffic/trunk/proxy/Main.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Main.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Main.cc (original)
+++ trafficserver/traffic/trunk/proxy/Main.cc Mon May 16 01:33:43 2011
@@ -1927,6 +1927,9 @@ main(int argc, char **argv)
     pmgmt->registerMgmtCallback(MGMT_EVENT_SHUTDOWN, mgmt_restart_shutdown_callback, NULL);
     pmgmt->registerMgmtCallback(MGMT_EVENT_RESTART, mgmt_restart_shutdown_callback, NULL);
 
+    // The main thread also becomes a net thread.
+    ink_set_thread_name("[ET_NET 0]");
+
     Note("traffic server running");
 
 #if TS_HAS_TESTS

Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc Mon May 16 01:33:43 2011
@@ -30,7 +30,8 @@ int
 RemapProcessor::start(int num_threads)
 {
   if (_use_separate_remap_thread)
-    ET_REMAP = eventProcessor.spawn_event_threads(num_threads);  // ET_REMAP is a class member
+    ET_REMAP = eventProcessor.spawn_event_threads(num_threads, "ET_REMAP");  // ET_REMAP
is a class member
+
   return 0;
 }
 

Modified: trafficserver/traffic/trunk/proxy/logging/Log.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/Log.cc?rev=1103590&r1=1103589&r2=1103590&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/Log.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/Log.cc Mon May 16 01:33:43 2011
@@ -983,7 +983,7 @@ Log::create_threads()
     ink_mutex_init(&flush_mutex, "Flush thread mutex");
     ink_cond_init(&flush_cond);
     Continuation *flush_continuation = NEW(new LoggingFlushContinuation);
-    Event *flush_event = eventProcessor.spawn_thread(flush_continuation);
+    Event *flush_event = eventProcessor.spawn_thread(flush_continuation, "[LOGGING]");
     flush_thread = flush_event->ethread->tid;
 
 #if !defined(IOCORE_LOG_COLLATION)



Mime
View raw message