Bug 1657521 - P3. Have the RemoteDecoderManagerChild use its own dedicated thread. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 13 Aug 2020 03:19:36 +0000
changeset 544480 d266ef2e9ad797b875934a9c24a12f9f27efdd50
parent 544479 233bb07b9bb931d853a956abf8a4cc8b0e73e919
child 544481 df297d346db2729d7c9b3a951321e6f49b59586e
push id37695
push usermalexandru@mozilla.com
push dateThu, 13 Aug 2020 09:29:15 +0000
treeherdermozilla-central@32ec11f12a62 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1657521, 1650996
milestone81.0a1
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
Bug 1657521 - P3. Have the RemoteDecoderManagerChild use its own dedicated thread. r=mattwoodrow This is a partial revert of "Bug 1650996 - P3. Have RemoteDecoderManagerChild use a TaskQueue over a media threadpool." The RemoteDecoderManagerChild dispatch tasks synchronously, right now it is doing so on the media controller's thread pool ; however in the following patch it will change the creation to the decoder's thread pool. If we attempt to instantiate too many decoders at once, we run out of available threads and dead-lock in the sync dispatch. This issue has bitten us in various places already and the solution was always assuming that the decoder will always be created on the controller's thread and used on the decoder's thread. This assumption won't hold any longer and was difficult to keep anyway. So we have the RemoteDecoderManagerChild uses a dedicated thread so that we can guarantee there will always be an available thread to create the decoder. Depends on D86543 Differential Revision: https://phabricator.services.mozilla.com/D86895
build/clang-plugin/ThreadAllows.txt
dom/media/ipc/RemoteDecoderManagerChild.cpp
--- a/build/clang-plugin/ThreadAllows.txt
+++ b/build/clang-plugin/ThreadAllows.txt
@@ -60,16 +60,17 @@ Permission
 PlayEventSound
 ProcessHangMon
 ProfSymbolTable
 ProfilerChild
 ProxyResolution
 RemoteLzyStream
 RWLockTester
 RacingServMan
+RemVidChild
 Sandbox Testing
 SaveScripts
 Socket Thread
 SpeechWorker
 SpinEventLoop
 StressRunner
 SuicideManager
 SuicideThread
--- a/dom/media/ipc/RemoteDecoderManagerChild.cpp
+++ b/dom/media/ipc/RemoteDecoderManagerChild.cpp
@@ -15,17 +15,17 @@
 #include "mozilla/layers/SynchronousTask.h"
 
 namespace mozilla {
 
 using namespace layers;
 using namespace gfx;
 
 // Only modified on the main-thread
-StaticRefPtr<TaskQueue> sRemoteDecoderManagerChildThread;
+StaticRefPtr<nsIThread> sRemoteDecoderManagerChildThread;
 
 // Only accessed from sRemoteDecoderManagerChildThread
 static StaticRefPtr<RemoteDecoderManagerChild>
     sRemoteDecoderManagerChildForRDDProcess;
 
 static StaticRefPtr<RemoteDecoderManagerChild>
     sRemoteDecoderManagerChildForGPUProcess;
 static UniquePtr<nsTArray<RefPtr<Runnable>>> sRecreateTasks;
@@ -34,19 +34,20 @@ static UniquePtr<nsTArray<RefPtr<Runnabl
 void RemoteDecoderManagerChild::InitializeThread() {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!sRemoteDecoderManagerChildThread) {
     // We can't use a MediaThreadType::CONTROLLER as the GpuDecoderModule and
     // RemoteDecoderModule runs on it and dispatch synchronous tasks to the
     // manager thread, should more than 4 concurrent videos being instantiated
     // at the same time, we could end up in a deadlock.
-    sRemoteDecoderManagerChildThread = new TaskQueue(
-        GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER), "RemVidChild");
-
+    RefPtr<nsIThread> childThread;
+    nsresult rv = NS_NewNamedThread("RemVidChild", getter_AddRefs(childThread));
+    NS_ENSURE_SUCCESS_VOID(rv);
+    sRemoteDecoderManagerChildThread = childThread;
     sRecreateTasks = MakeUnique<nsTArray<RefPtr<Runnable>>>();
   }
 }
 
 /* static */
 void RemoteDecoderManagerChild::InitForRDDProcess(
     Endpoint<PRemoteDecoderManagerChild>&& aVideoManager) {
   InitializeThread();
@@ -79,18 +80,17 @@ void RemoteDecoderManagerChild::Shutdown
               sRemoteDecoderManagerChildForRDDProcess = nullptr;
               if (sRemoteDecoderManagerChildForGPUProcess &&
                   sRemoteDecoderManagerChildForGPUProcess->CanSend()) {
                 sRemoteDecoderManagerChildForGPUProcess->Close();
               }
               sRemoteDecoderManagerChildForGPUProcess = nullptr;
             })));
 
-    sRemoteDecoderManagerChildThread->BeginShutdown();
-    sRemoteDecoderManagerChildThread->AwaitShutdownAndIdle();
+    sRemoteDecoderManagerChildThread->Shutdown();
     sRemoteDecoderManagerChildThread = nullptr;
 
     sRecreateTasks = nullptr;
   }
 }
 
 void RemoteDecoderManagerChild::RunWhenGPUProcessRecreated(
     already_AddRefed<Runnable> aTask) {