Backed out changeset 8be35539cc88 (bug 1124880) for build bustage CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Thu, 26 Mar 2015 12:47:53 -0700
changeset 264860 5044ad98d16015c6428c2957176c60e12f237ebf
parent 264859 821bb2b2dca684132d7abcaeb550fca8916ba393
child 264861 1723cae4f6b2ef5c77d3ed006ac215d1a7eef8c3
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1124880
milestone39.0a1
backs out8be35539cc88d9b77a3d7018fb1b5ffd980f057d
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 8be35539cc88 (bug 1124880) for build bustage CLOSED TREE
netwerk/base/nsUDPSocket.cpp
toolkit/components/telemetry/Histograms.json
--- a/netwerk/base/nsUDPSocket.cpp
+++ b/netwerk/base/nsUDPSocket.cpp
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Endian.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/HoldDropJSObjects.h"
-#include "mozilla/Telemetry.h"
 
 #include "nsSocketTransport2.h"
 #include "nsUDPSocket.h"
 #include "nsProxyRelease.h"
 #include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsNetCID.h"
 #include "prnetdb.h"
@@ -82,201 +81,16 @@ public:
   }
 
 private:
   nsRefPtr<nsUDPSocket> mSocket;
   PRSocketOptionData    mOpt;
 };
 
 //-----------------------------------------------------------------------------
-// nsUDPSocketCloseThread
-//-----------------------------------------------------------------------------
-
-// A helper class carrying call to PR_Close on nsUDPSocket's FD to a separate
-// thread.  This may be a workaround for shutdown blocks that are caused by
-// serial calls to close on UDP sockets.
-// It starts an NSPR thread for each socket and also adds itself as an observer
-// to "xpcom-shutdown-threads" notification where we join the thread (if not
-// already done). During worktime of the thread the class is also
-// self-referenced, since observer service might throw the reference away
-// sooner than the thread is actually done.
-class nsUDPSocketCloseThread : public nsIObserver
-{
-public:
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  static bool Close(PRFileDesc *aFd);
-
-private:
-  explicit nsUDPSocketCloseThread(PRFileDesc *aFd);
-  virtual ~nsUDPSocketCloseThread() { }
-
-  bool Begin();
-  void ThreadFunc();
-  void AddObserver();
-  void JoinAndRemove();
-
-  static void ThreadFunc(void *aClosure)
-    { static_cast<nsUDPSocketCloseThread*>(aClosure)->ThreadFunc(); }
-
-  // Socket to close.
-  PRFileDesc *mFd;
-  PRThread *mThread;
-
-  // Self reference, added before we create the thread, dropped
-  // after the thread is done (from the thread).  No races, since
-  // mSelf is assigned bofore the thread func is executed and
-  // released only on the thread func.
-  nsRefPtr<nsUDPSocketCloseThread> mSelf;
-
-  // Telemetry probes.
-  TimeStamp mBeforeClose;
-  TimeStamp mAfterClose;
-
-  // Switches to true on "xpcom-shutdown-threads" notification and since
-  // then it makes the code fallback to a direct call to PR_Close().
-  static bool sPastShutdown;
-
-  // Active threads (roughly) counter, modified only on the main thread
-  // and used only for telemetry reports.
-  static uintptr_t sActiveThreadsCount;
-};
-
-uint32_t nsUDPSocketCloseThread::sActiveThreadsCount = 0;
-bool nsUDPSocketCloseThread::sPastShutdown = false;
-
-NS_IMPL_ISUPPORTS(nsUDPSocketCloseThread, nsIObserver);
-
-bool
-nsUDPSocketCloseThread::Close(PRFileDesc *aFd)
-{
-  if (sPastShutdown) {
-    return false;
-  }
-
-  nsRefPtr<nsUDPSocketCloseThread> t = new nsUDPSocketCloseThread(aFd);
-  return t->Begin();
-}
-
-nsUDPSocketCloseThread::nsUDPSocketCloseThread(PRFileDesc *aFd)
-  : mFd(aFd)
-  , mThread(nullptr)
-{
-}
-
-bool
-nsUDPSocketCloseThread::Begin()
-{
-  // Observer service must be worked with on the main thread only.
-  // This method is called usually on the socket thread.
-  // Register us before the thread starts.  It may happen the thread is
-  // done and posts removal event sooner then we would post this event
-  // after the thread creation.
-  nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(
-    this, &nsUDPSocketCloseThread::AddObserver);
-  if (event) {
-    NS_DispatchToMainThread(event);
-  }
-
-  // Keep us self-referenced during lifetime of the thread.
-  // Released after the thread is done.
-  mSelf = this;
-  mThread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
-                            PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
-                            PR_JOINABLE_THREAD, 4 * 4096);
-  if (!mThread) {
-    // This doesn't join since there is no thread, just removes
-    // this class as an observer.
-    JoinAndRemove();
-    mSelf = nullptr;
-    return false;
-  }
-
-  return true;
-}
-
-void
-nsUDPSocketCloseThread::AddObserver()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ++sActiveThreadsCount;
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (obs) {
-    obs->AddObserver(this, "xpcom-shutdown-threads", false);
-  }
-}
-
-void
-nsUDPSocketCloseThread::JoinAndRemove()
-{
-  // Posted from the particular (this) UDP close socket when it's done
-  // or from "xpcom-shutdown-threads" notification.
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mThread) {
-    PR_JoinThread(mThread);
-    mThread = nullptr;
-
-    Telemetry::Accumulate(Telemetry::UDP_SOCKET_PARALLEL_CLOSE_COUNT, sActiveThreadsCount);
-    Telemetry::AccumulateTimeDelta(Telemetry::UDP_SOCKET_CLOSE_TIME, mBeforeClose, mAfterClose);
-
-    MOZ_ASSERT(sActiveThreadsCount > 0);
-    --sActiveThreadsCount;
-  }
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (obs) {
-    obs->RemoveObserver(this, "xpcom-shutdown-threads");
-  }
-}
-
-NS_IMETHODIMP
-nsUDPSocketCloseThread::Observe(nsISupports *aSubject,
-                                const char *aTopic,
-                                const char16_t *aData)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!strcmp(aTopic, "xpcom-shutdown-threads")) {
-    sPastShutdown = true;
-    JoinAndRemove();
-    return NS_OK;
-  }
-
-  MOZ_CRASH("Unexpected observer topic");
-  return NS_OK;
-}
-
-void
-nsUDPSocketCloseThread::ThreadFunc()
-{
-  PR_SetCurrentThreadName("UDP socket close");
-
-  mBeforeClose = TimeStamp::Now();
-
-  PR_Close(mFd);
-  mFd = nullptr;
-
-  mAfterClose = TimeStamp::Now();
-
-  // Join and remove the observer on the main thread.
-  nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(
-    this, &nsUDPSocketCloseThread::JoinAndRemove);
-  if (event) {
-    NS_DispatchToMainThread(event);
-  }
-
-  // Thread's done, release the self-reference.
-  mSelf = nullptr;
-}
-
-//-----------------------------------------------------------------------------
 // nsUDPOutputStream impl
 //-----------------------------------------------------------------------------
 NS_IMPL_ISUPPORTS(nsUDPOutputStream, nsIOutputStream)
 
 nsUDPOutputStream::nsUDPOutputStream(nsUDPSocket* aSocket,
                                      PRFileDesc* aFD,
                                      PRNetAddr& aPrClientAddr)
   : mSocket(aSocket)
@@ -456,19 +270,17 @@ nsUDPSocket::nsUDPSocket()
 
   mSts = gSocketTransportService;
   MOZ_COUNT_CTOR(nsUDPSocket);
 }
 
 nsUDPSocket::~nsUDPSocket()
 {
   if (mFD) {
-    if (!nsUDPSocketCloseThread::Close(mFD)) {
-      PR_Close(mFD);
-    }
+    PR_Close(mFD);
     mFD = nullptr;
   }
 
   MOZ_COUNT_DTOR(nsUDPSocket);
 }
 
 void
 nsUDPSocket::AddOutputBytes(uint64_t aBytes)
@@ -700,19 +512,17 @@ nsUDPSocket::OnSocketDetached(PRFileDesc
 {
   // force a failure condition if none set; maybe the STS is shutting down :-/
   if (NS_SUCCEEDED(mCondition))
     mCondition = NS_ERROR_ABORT;
 
   if (mFD)
   {
     NS_ASSERTION(mFD == fd, "wrong file descriptor");
-    if (!nsUDPSocketCloseThread::Close(mFD)) {
-      PR_Close(mFD);
-    }
+    PR_Close(mFD);
     mFD = nullptr;
   }
 
   if (mListener)
   {
     // need to atomically clear mListener.  see our Close() method.
     nsCOMPtr<nsIUDPSocketListener> listener;
     {
@@ -840,18 +650,16 @@ nsUDPSocket::Close()
   {
     MutexAutoLock lock(mLock);
     // we want to proxy the close operation to the socket thread if a listener
     // has been set.  otherwise, we should just close the socket here...
     if (!mListener)
     {
       if (mFD)
       {
-        // Here we want to go directly with closing the socket since some tests
-        // expects this happen synchronously.
         PR_Close(mFD);
         mFD = nullptr;
       }
       return NS_OK;
     }
   }
   return PostEvent(this, &nsUDPSocket::OnMsgClose);
 }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7686,24 +7686,10 @@
     "kind": "count",
     "description": "Count slow script notices"
   },
   "PLUGIN_HANG_NOTICE_COUNT": {
     "alert_emails": ["perf-telemetry-alerts@mozilla.com"],
     "expires_in_version": "never",
     "kind": "count",
     "description": "Count plugin hang notices in e10s"
-  },
-  "UDP_SOCKET_PARALLEL_CLOSE_COUNT": {
-    "expires_in_version": "41",
-    "kind": "linear",
-    "high": "20",
-    "n_buckets": 19,
-    "description": "Number of concurrent UDP socket closing threads"
-  },
-  "UDP_SOCKET_CLOSE_TIME": {
-    "expires_in_version": "45",
-    "kind": "exponential",
-    "high": "60000",
-    "n_buckets": 30,
-    "description": "Time PR_Close of a UDP socket taken (ms)"
   }
 }