You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2011/08/10 23:03:04 UTC

svn commit: r1156365 - in /trafficserver/traffic/trunk: iocore/eventsystem/ iocore/net/ proxy/http/

Author: zwoop
Date: Wed Aug 10 21:03:04 2011
New Revision: 1156365

URL: http://svn.apache.org/viewvc?rev=1156365&view=rev
Log:
TS-911 Remove unecessary lock in HTTP accept, and cleanup

Modified:
    trafficserver/traffic/trunk/iocore/eventsystem/I_Lock.h
    trafficserver/traffic/trunk/iocore/net/P_NetAccept.h
    trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc
    trafficserver/traffic/trunk/proxy/http/HttpClientSession.h

Modified: trafficserver/traffic/trunk/iocore/eventsystem/I_Lock.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/I_Lock.h?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/I_Lock.h (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/I_Lock.h Wed Aug 10 21:03:04 2011
@@ -65,10 +65,9 @@ extern void lock_taken(const char *file,
   allow you to lock/unlock the underlying mutex object.
 
 */
-class ProxyMutex:public RefCountObj
+class ProxyMutex: public RefCountObj
 {
 public:
-
   /**
     Underlying mutex object.
 
@@ -87,7 +86,7 @@ public:
 
   */
   volatile EThreadPtr thread_holding;
-
+  
   int nthread_holding;
 
 #ifdef DEBUG
@@ -118,7 +117,7 @@ public:
     new_ProxyMutex function, which provides a faster allocation.
 
   */
-    ProxyMutex()
+  ProxyMutex()
   {
     thread_holding = NULL;
     nthread_holding = 0;
@@ -172,14 +171,15 @@ extern inkcoreapi ClassAllocator<ProxyMu
 class ProxyMutexPtr
 {
 public:
-
   /**
     Constructor of the ProxyMutexPtr class. You can provide a pointer
     to a ProxyMutex object or set it at a later time with the
     assignment operator.
 
   */
-ProxyMutexPtr(ProxyMutex * ptr = 0):m_ptr(ptr) {
+  ProxyMutexPtr(ProxyMutex * ptr = 0)
+    : m_ptr(ptr)
+  {
     if (m_ptr)
       REF_COUNT_OBJ_REFCOUNT_INC(m_ptr);
   }
@@ -194,7 +194,8 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
     @param src Constant ref to the ProxyMutexPtr to initialize from.
 
   */
-  ProxyMutexPtr(const ProxyMutexPtr & src):m_ptr(src.m_ptr)
+  ProxyMutexPtr(const ProxyMutexPtr & src)
+    : m_ptr(src.m_ptr)
   {
     if (m_ptr)
       REF_COUNT_OBJ_REFCOUNT_INC(m_ptr);
@@ -206,7 +207,8 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
     reference to the object (reference count equal to zero).
 
   */
-  ~ProxyMutexPtr() {
+  ~ProxyMutexPtr()
+  {
     if (m_ptr && !m_ptr->refcount_dec())
       m_ptr->free();
   }
@@ -222,7 +224,8 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
     @param p The reference to the ProxyMutex object.
 
   */
-  ProxyMutexPtr & operator =(ProxyMutex * p) {
+  ProxyMutexPtr & operator =(ProxyMutex * p)
+  {
     ProxyMutex *temp_ptr = m_ptr;
     if (m_ptr == p)
       return (*this);
@@ -246,7 +249,8 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
     @param src The ProxyMutexPtr to get the ProxyMutex reference from.
 
   */
-  ProxyMutexPtr & operator =(const ProxyMutexPtr & src) {
+  ProxyMutexPtr & operator =(const ProxyMutexPtr & src)
+  {
     return (operator =(src.m_ptr));
   }
 
@@ -281,7 +285,7 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
   */
   operator  ProxyMutex *() const
   {
-    return (m_ptr);
+    return m_ptr;
   }
 
   /**
@@ -294,7 +298,7 @@ ProxyMutexPtr(ProxyMutex * ptr = 0):m_pt
   */
   ProxyMutex *operator ->() const
   {
-    return (m_ptr);
+    return m_ptr;
   }
 
   /**
@@ -574,19 +578,14 @@ struct MutexLock
     m.clear();
   }
 
-  ~MutexLock() {
+  ~MutexLock()
+  {
     if (m)
       Mutex_unlock(m, m->thread_holding);
   }
 
-  int operator!()
-  {
-    return false;
-  }
-  operator  bool()
-  {
-    return true;
-  }
+  int operator!() const { return false; }
+  operator bool() { return true; }
 };
 
 struct MutexTryLock
@@ -624,7 +623,8 @@ struct MutexTryLock
         m = am;
   }
 
-  ~MutexTryLock() {
+  ~MutexTryLock()
+  {
     if (m.m_ptr)
       Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding);
   }
@@ -638,14 +638,8 @@ struct MutexTryLock
     lock_acquired = false;
   }
 
-  int operator!()
-  {
-    return !lock_acquired;
-  }
-  operator  bool()
-  {
-    return lock_acquired;
-  }
+  int operator!() const { return !lock_acquired; }
+  operator bool() const { return lock_acquired; }
 };
 
 inline void

Modified: trafficserver/traffic/trunk/iocore/net/P_NetAccept.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/P_NetAccept.h?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/P_NetAccept.h (original)
+++ trafficserver/traffic/trunk/iocore/net/P_NetAccept.h Wed Aug 10 21:03:04 2011
@@ -114,7 +114,7 @@ struct NetAccept:public Continuation
   // 0 == success
   int do_listen(bool non_blocking, bool transparent = false);
 
-  int do_blocking_accept(NetAccept * master_na, EThread * t);
+  int do_blocking_accept(EThread * t);
   virtual int acceptEvent(int event, void *e);
   virtual int acceptFastEvent(int event, void *e);
   int acceptLoopEvent(int event, Event * e);

Modified: trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc Wed Aug 10 21:03:04 2011
@@ -397,7 +397,6 @@ SSLNetVConnection::free(EThread * t) {
   got_local_addr = 0;
   read.vio.mutex.clear();
   write.vio.mutex.clear();
-  action_.mutex.clear();
   this->mutex.clear();
   flags = 0;
   SET_CONTINUATION_HANDLER(this, (SSLNetVConnHandler) & SSLNetVConnection::startEvent);

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetAccept.cc Wed Aug 10 21:03:04 2011
@@ -147,24 +147,6 @@ Ldone:
 }
 
 
-//
-// Special purpose MAIN proxy accept code
-// Seperate accept thread function
-//
-int
-net_accept_main_blocking(NetAccept * na, Event * e, bool blockable)
-{
-  (void) blockable;
-  (void) e;
-
-  EThread *t = this_ethread();
-
-  while (1)
-    na->do_blocking_accept(na, t);
-  return -1;
-}
-
-
 UnixNetVConnection *
 NetAccept::allocateThread(EThread * t)
 {
@@ -201,10 +183,6 @@ EventType NetAccept::getEtype()
 void
 NetAccept::init_accept_loop()
 {
-  if (!action_->continuation->mutex) {
-    action_->continuation->mutex = new_ProxyMutex();
-    action_->mutex = action_->continuation->mutex;
-  }
   SET_CONTINUATION_HANDLER(this, &NetAccept::acceptLoopEvent);
   eventProcessor.spawn_thread(this, "[ACCEPT]");
 }
@@ -293,7 +271,7 @@ NetAccept::do_listen(bool non_blocking, 
 
 
 int
-NetAccept::do_blocking_accept(NetAccept * master_na, EThread * t)
+NetAccept::do_blocking_accept(EThread * t)
 {
   int res = 0;
   int loop = accept_till_done;
@@ -302,13 +280,13 @@ NetAccept::do_blocking_accept(NetAccept 
   //do-while for accepting all the connections
   //added by YTS Team, yamsat
   do {
-    vc = (UnixNetVConnection *) master_na->alloc_cache;
+    vc = (UnixNetVConnection *)alloc_cache;
     if (likely(!vc)) {
       //vc = allocateThread(t);
       vc = allocateGlobal(); // Bypass proxy / thread allocator
       vc->from_accept_thread = true;
       vc->id = net_next_connection_number();
-      master_na->alloc_cache = vc;
+      alloc_cache = vc;
     }
     ink_hrtime now = ink_get_hrtime();
 
@@ -340,18 +318,18 @@ NetAccept::do_blocking_accept(NetAccept 
       return -1;
     }
     check_emergency_throttle(vc->con);
-    master_na->alloc_cache = NULL;
+    alloc_cache = NULL;
 
     NET_SUM_GLOBAL_DYN_STAT(net_connections_currently_open_stat, 1);
     vc->submit_time = now;
     vc->ip = ((struct sockaddr_in *)(&(vc->con.sa)))->sin_addr.s_addr;
     vc->port = ntohs(((struct sockaddr_in *)(&(vc->con.sa)))->sin_port);
     vc->accept_port = ntohs(((struct sockaddr_in *)(&(server.sa)))->sin_port);
-    vc->set_is_transparent(master_na->server.f_inbound_transparent);
-    vc->set_is_other_side_transparent(master_na->server.f_outbound_transparent);
+    vc->set_is_transparent(server.f_inbound_transparent);
+    vc->set_is_other_side_transparent(server.f_outbound_transparent);
     Debug("http_tproxy", "Marking accepted %sconnection on %x as%s outbound transparent.\n",
-	  master_na->server.f_inbound_transparent ? "inbound transparent " : "",
-	  master_na, master_na->server.f_outbound_transparent ? "" : " not"
+	  server.f_inbound_transparent ? "inbound transparent " : "",
+	  this, server.f_outbound_transparent ? "" : " not"
 	  );
     vc->mutex = new_ProxyMutex();
     vc->action_ = *action_;
@@ -543,9 +521,12 @@ NetAccept::acceptLoopEvent(int event, Ev
 {
   (void) event;
   (void) e;
+  EThread *t = this_ethread();
+
   while (1)
-    if (net_accept_main_blocking(this, e, true) < 0)
-      break;
+    do_blocking_accept(t);
+
+  // Don't think this ever happens ...
   NET_DECREMENT_DYN_STAT(net_accepts_currently_open_stat);
   delete this;
   return EVENT_DONE;

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc Wed Aug 10 21:03:04 2011
@@ -106,7 +106,7 @@ NetProcessor::accept(Continuation * cont
 }
 
 Action *
-NetProcessor::main_accept(Continuation * cont, SOCKET fd, sockaddr * bound_sockaddr, int *bound_sockaddr_size,
+NetProcessor::main_accept(Continuation *cont, SOCKET fd, sockaddr *bound_sockaddr, int *bound_sockaddr_size,
                           bool accept_only, bool localhost_only, AcceptOptions const& opt)
 {
   (void) accept_only;           // NT only
@@ -138,7 +138,7 @@ NetProcessor::main_accept(Continuation *
 
 
 Action *
-UnixNetProcessor::accept_internal(Continuation * cont,
+UnixNetProcessor::accept_internal(Continuation *cont,
                                   int fd,
                                   struct sockaddr * bound_sockaddr,
                                   int *bound_sockaddr_size,

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc Wed Aug 10 21:03:04 2011
@@ -893,10 +893,9 @@ int
 UnixNetVConnection::startEvent(int event, Event *e)
 {
   (void) event;
-  MUTEX_TRY_LOCK(lock, action_.mutex, e->ethread);
-  MUTEX_TRY_LOCK(lock2, get_NetHandler(e->ethread)->mutex, e->ethread);
 
-  if (!lock || !lock2) {
+  MUTEX_TRY_LOCK(lock, get_NetHandler(e->ethread)->mutex, e->ethread);
+  if (!lock) {
     e->schedule_in(NET_RETRY_DELAY);
     return EVENT_CONT;
   }
@@ -912,9 +911,9 @@ UnixNetVConnection::acceptEvent(int even
 {
   (void) event;
   thread = e->ethread;
-  MUTEX_TRY_LOCK(lock, action_.mutex, e->ethread);
-  MUTEX_TRY_LOCK(lock2, get_NetHandler(thread)->mutex, e->ethread);
-  if (!lock || !lock2) {
+
+  MUTEX_TRY_LOCK(lock, get_NetHandler(thread)->mutex, e->ethread);
+  if (!lock) {
     if (event == EVENT_NONE) {
       thread->schedule_in(this, NET_RETRY_DELAY);
       return EVENT_DONE;
@@ -1098,7 +1097,6 @@ UnixNetVConnection::free(EThread *t)
   got_local_addr = 0;
   read.vio.mutex.clear();
   write.vio.mutex.clear();
-  action_.mutex.clear();
   this->mutex.clear();
   flags = 0;
   accept_port = 0;

Modified: trafficserver/traffic/trunk/proxy/http/HttpClientSession.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpClientSession.h?rev=1156365&r1=1156364&r2=1156365&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpClientSession.h (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpClientSession.h Wed Aug 10 21:03:04 2011
@@ -56,10 +56,9 @@ public:
   static HttpClientSession *allocate();
 
 public:
-  void new_connection(NetVConnection * new_vc, bool backdoor);
+  void new_connection(NetVConnection * new_vc, bool backdoor = false);
 
   virtual VIO *do_io_read(Continuation * c, int64_t nbytes = INT64_MAX, MIOBuffer * buf = 0);
-
   virtual VIO *do_io_write(Continuation * c = NULL, int64_t nbytes = INT64_MAX, IOBufferReader * buf = 0, bool owner = false);
 
   virtual void do_io_close(int lerrno = -1);