Closed
Bug 1151656
Opened 9 years ago
Closed 9 years ago
Build a mechanism to coalesce runnable dispatch to the tail end of a task
Categories
(Core :: Audio/Video, defect)
Tracking
()
RESOLVED
FIXED
mozilla40
Tracking | Status | |
---|---|---|
firefox40 | --- | fixed |
People
(Reporter: bholley, Assigned: bholley)
References
Details
Attachments
(9 files, 1 obsolete file)
5.43 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
4.00 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
5.16 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
6.87 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
5.67 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
3.96 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
5.94 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
19.04 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
36.61 KB,
patch
|
mattwoodrow
:
review+
|
Details | Diff | Splinter Review |
This is a prerequisite to bug 1144481 to get the necessary atomicity when inspecting mirrored state. I'd originally rolled this work into that bug, but I think it's tricky enough that it's good milestone all on its own.
Assignee | ||
Updated•9 years ago
|
Summary: Build mechanism to coalesce runnable dispatch to the tail end of a task → Build a mechanism to coalesce runnable dispatch to the tail end of a task
Assignee | ||
Comment 1•9 years ago
|
||
Green try push: https://treeherder.mozilla.org/#/jobs?repo=try&revision=fbff16cd9779
Assignee | ||
Comment 2•9 years ago
|
||
Attachment #8589993 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 3•9 years ago
|
||
Attachment #8589994 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 4•9 years ago
|
||
Attachment #8589995 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 5•9 years ago
|
||
I think this will generally be useful for asserting things. If we're concerned about the TLS overhead we could make it debug-only, but my sense is that it's negligible.
Attachment #8589996 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 6•9 years ago
|
||
Attachment #8589997 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 7•9 years ago
|
||
Attachment #8589998 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 8•9 years ago
|
||
In order to make sure that the MDSM properly dispatches everything via tail dispatch, we want verification that is more robust than simple inspection.
Attachment #8590000 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 9•9 years ago
|
||
Attachment #8590001 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 10•9 years ago
|
||
Attachment #8590002 -
Flags: review?(matt.woodrow)
Assignee | ||
Comment 11•9 years ago
|
||
The green try push above didn't include a couple of last-minute modifications to part 9. Another try push [1] did include them, and I noticed an occasional assertion failure from failed dispatch on the audio thread. Annotated that assertion not to fire, since presumably this has always been failing. [1] https://treeherder.mozilla.org/#/jobs?repo=try&revision=7667e9c0d13e
Attachment #8590002 -
Attachment is obsolete: true
Attachment #8590002 -
Flags: review?(matt.woodrow)
Attachment #8590006 -
Flags: review?(matt.woodrow)
Updated•9 years ago
|
Attachment #8589993 -
Flags: review?(matt.woodrow) → review+
Updated•9 years ago
|
Attachment #8589994 -
Flags: review?(matt.woodrow) → review+
Updated•9 years ago
|
Attachment #8589995 -
Flags: review?(matt.woodrow) → review+
Comment 12•9 years ago
|
||
Comment on attachment 8589996 [details] [diff] [review] Part 4 - Implement the ability to get the currently running task queue. v1 Review of attachment 8589996 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/MediaTaskQueue.h @@ +34,5 @@ > + static void InitStatics(); > + > + // Returns the task queue that the caller is currently running in, or null > + // if the caller is not running in a MediaTaskQueue. > + static MediaTaskQueue* CurrentQueueOrNull() { return sCurrentQueueTLS.get(); } Any particular reason for this naming? The normal convention is that GetFoo() can return nullptr, and Foo() is infallible.
Attachment #8589996 -
Flags: review?(matt.woodrow) → review+
Assignee | ||
Comment 13•9 years ago
|
||
(In reply to Matt Woodrow (:mattwoodrow) from comment #12) > Any particular reason for this naming? The normal convention is that > GetFoo() can return nullptr, and Foo() is infallible. It's a JS/XPConnect convention, used to indicate that the method cannot fail, but that one of the valid values is null. If you think it's too incongruous, I can switch it to GetCurrentQueue.
Comment 14•9 years ago
|
||
Comment on attachment 8589997 [details] [diff] [review] Part 5 - Implement TaskDispatcher.h. v1 Review of attachment 8589997 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/TaskDispatcher.h @@ +24,5 @@ > + * there are sometimes reasons why we might want to delay the actual dispatch of > + * these tasks until a specified moment. At present, there are two reasons to do > + * this: > + * > + * XXXbholley - Finish me! Yes bobby, please do :)
Attachment #8589997 -
Flags: review?(matt.woodrow) → review+
Comment 15•9 years ago
|
||
(In reply to Bobby Holley (:bholley) from comment #13) > > It's a JS/XPConnect convention, used to indicate that the method cannot > fail, but that one of the valid values is null. If you think it's too > incongruous, I can switch it to GetCurrentQueue. Ok, I haven't seen that much in layout/media/gfx code. I'd prefer GetCurrentQueue(), but it's not a big deal.
Assignee | ||
Comment 16•9 years ago
|
||
(In reply to Matt Woodrow (:mattwoodrow) from comment #15) > Ok, I haven't seen that much in layout/media/gfx code. I'd prefer > GetCurrentQueue(), but it's not a big deal. Sure thing. (In reply to Matt Woodrow (:mattwoodrow) from comment #14) > Yes bobby, please do :) Oops. ;-)
Updated•9 years ago
|
Attachment #8589998 -
Flags: review?(matt.woodrow) → review+
Updated•9 years ago
|
Attachment #8590000 -
Flags: review?(matt.woodrow) → review+
Updated•9 years ago
|
Attachment #8590001 -
Flags: review?(matt.woodrow) → review+
Comment 17•9 years ago
|
||
Comment on attachment 8590006 [details] [diff] [review] Part 9 - Use TailDispatch for the MDSM's task queue. v2 Review of attachment 8590006 [details] [diff] [review]: ----------------------------------------------------------------- It's a little annoying that we have to change all the call sites (and thus rely on 100% code coverage during debug tests to be sure that we got them all), but I don't have any better ideas.
Attachment #8590006 -
Flags: review?(matt.woodrow) → review+
Assignee | ||
Comment 18•9 years ago
|
||
Thanks for the reviews matt! remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/fe38ca71a1d4 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/e72d7aa5f4e3 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/defb154dbaa8 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/94128d385667 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/1c6ee34874d8 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/fd5e9c300a80 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/9b43eca6d969 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/8b257d977271 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/8c22476cabca
Comment 19•9 years ago
|
||
Comment on attachment 8589996 [details] [diff] [review] Part 4 - Implement the ability to get the currently running task queue. v1 Review of attachment 8589996 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/AbstractThread.cpp @@ +28,5 @@ > bool > AbstractThreadImpl<nsIThread>::IsCurrentThreadIn() > { > + bool in = NS_GetCurrentThread() == mTarget; > + MOZ_ASSERT_IF(in, MediaTaskQueue::CurrentQueueOrNull() == nullptr); How does MediaTaskQueue come into play when AbstractThread is concerned here? ::: dom/media/MediaTaskQueue.cpp @@ +206,5 @@ > MediaTaskQueue::IsCurrentThreadIn() > { > MonitorAutoLock mon(mQueueMonitor); > + bool in = NS_GetCurrentThread() == mRunningThread; > + MOZ_ASSERT_IF(in, CurrentQueueOrNull() == this); This looks suspicious to me. If we exit the funciton at [1], next runnable (not those dispatched to MediaTaskQueue) in the same thread will see |NS_GetCurrentThread() == mRunningThread| while CurrentQueueOrNull() would return null. [1] https://hg.mozilla.org/mozilla-central/file/2c92a7df87c9/dom/media/MediaTaskQueue.cpp#l214
Comment 20•9 years ago
|
||
Comment on attachment 8589997 [details] [diff] [review] Part 5 - Implement TaskDispatcher.h. v1 Review of attachment 8589997 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/TaskDispatcher.h @@ +132,5 @@ > + > + PerThreadTaskGroup& EnsureTaskGroup(AbstractThread* aThread) > + { > + for (size_t i = 0; i < mTaskGroups.Length(); ++i) { > + if (mTaskGroups[i]->mThread == aThread) { This comparison is not reliable. Atomicy will be broken if we accidentially have 2 AbstractThread instances associated with the same nsIThread such as the main thread.
Comment 21•9 years ago
|
||
Comment on attachment 8590000 [details] [diff] [review] Part 7 - Implement the ability to assert tail dispatch. v1 Review of attachment 8590000 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/AbstractThread.cpp @@ +19,5 @@ > template<> > nsresult > AbstractThreadImpl<nsIThread>::Dispatch(already_AddRefed<nsIRunnable> aRunnable) > { > + MediaTaskQueue::AssertInTailDispatchIfNeeded(); Why this check here? Shouldn't it be done in mTarget->Dispatch() if mTarget happens to be a MediaTaskQueue.
Comment 22•9 years ago
|
||
Comment on attachment 8590001 [details] [diff] [review] Part 8 - Make MediaPromises operate with TaskDispatchers. v1 Review of attachment 8590001 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/MediaPromise.h @@ +319,5 @@ > + // target for race bugs. So we do an extra assertion here to make sure our > + // caller is using tail dispatch correctly no matter what, rather than > + // relying on the assertion in Dispatch(), which may be called extremely > + // infrequently. > + aDispatcher.AssertIsTailDispatcherIfRequired(); Can this be done outside the lock?
Comment 23•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/fe38ca71a1d4 https://hg.mozilla.org/mozilla-central/rev/e72d7aa5f4e3 https://hg.mozilla.org/mozilla-central/rev/defb154dbaa8 https://hg.mozilla.org/mozilla-central/rev/94128d385667 https://hg.mozilla.org/mozilla-central/rev/1c6ee34874d8 https://hg.mozilla.org/mozilla-central/rev/fd5e9c300a80 https://hg.mozilla.org/mozilla-central/rev/9b43eca6d969 https://hg.mozilla.org/mozilla-central/rev/8b257d977271 https://hg.mozilla.org/mozilla-central/rev/8c22476cabca
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox40:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla40
Assignee | ||
Comment 24•9 years ago
|
||
(In reply to JW Wang [:jwwang] from comment #19) > Comment on attachment 8589996 [details] [diff] [review] > Part 4 - Implement the ability to get the currently running task queue. v1 > > Review of attachment 8589996 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: dom/media/AbstractThread.cpp > @@ +28,5 @@ > > bool > > AbstractThreadImpl<nsIThread>::IsCurrentThreadIn() > > { > > + bool in = NS_GetCurrentThread() == mTarget; > > + MOZ_ASSERT_IF(in, MediaTaskQueue::CurrentQueueOrNull() == nullptr); > > How does MediaTaskQueue come into play when AbstractThread is concerned here? This is just a useful way to assert that MediaTaskQueue::CurrentQueueOrNull (which has since been renamed MediaTaskQueue::GetCurrentQueue) returns null when we're on the main thread. > This looks suspicious to me. If we exit the funciton at [1], next runnable > (not those dispatched to MediaTaskQueue) in the same thread will see > |NS_GetCurrentThread() == mRunningThread| while CurrentQueueOrNull() would > return null. > > [1] https://hg.mozilla.org/mozilla-central/file/2c92a7df87c9/dom/media/MediaTaskQueue.cpp#l214 Yeah, seems like we should just make the management of mRunningThread safer. (In reply to JW Wang [:jwwang] from comment #20) > This comparison is not reliable. Atomicy will be broken if we accidentially > have 2 AbstractThread instances associated with the same nsIThread such as > the main thread. Good catch! I think this is enough of a footgun that we should just remove ::Create and allow == checks. We can revisit this problem if we ever need an nsIThread other than the main thread. (In reply to JW Wang [:jwwang] from comment #21) > Why this check here? Shouldn't it be done in mTarget->Dispatch() if mTarget > happens to be a MediaTaskQueue. No. This check is about the caller, not the dispatch target. We need to enforce this property whenever the MDSM task queue dispatches something, even if the dispatch target is the main thread. (In reply to JW Wang [:jwwang] from comment #22) > Can this be done outside the lock? Good idea. I'll file a followup bug to make these improvements.
You need to log in
before you can comment on or make changes to this bug.
Description
•