Closed Bug 1569819 Opened 5 years ago Closed 3 years ago

Divert WASM offthread compile tasks to use the XPCOM helper thread pool

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED DUPLICATE of bug 1713335

People

(Reporter: KrisWright, Assigned: allstars.chh)

References

Details

Attachments

(1 file)

We would like to divert the offthread WASM tasks to use the HelperThread pool. For this purpose, we've registered HelperThreadTaskCallback to pass any RunnableTask* to the task handler [1].

GlobalHelperThreadState categorizes three kinds of WASM tasks: tier1, tier2, and tier2 generator, as outlined in TaskSpecs[]. Tier 1 and tier 2 tasks are both a wasm::CompileTask pointer passed through in js::StartOffthreadWasmCompile(...) and tier 2 generators start in js::StartOffthreadWasmTier2Generator(...), which takes a wasm::UniqueTier2GeneratorTask.

The process for CompileTasks seems straightforward:

  1. Check for HelperThreadTaskCallback in js::StartOffThreadWasmCompile(...) [2] and if the callback exists, call the function to divert the tasks to the task handler in XPConnect.
  2. In native Spidermonkey, HandleWasmWorkload(...) checks to see if the task can start based on its compile mode [3]. I don't know enough about WASM to know how important this would be to the XPCOM thread pool. Since ThreadType is exposed to HelperThreadPool through the RunnableTask interface, HelperThreadTaskHandler should be able to check for this if it needs to.
  3. HelperThreadTaskHandler::run() assumes that tasks will destroy themselves or complete whatever end behavior they have, so it just forgets about the RunnableTask pointer [4]. If there is any additional end behavior that needs to be added, this will need to be handled by the CompileTask.

Tier 2 generators follow much of the same pattern (divert the task, check if the task can start, run the task) but GlobalHelperThreadState calls CancelOffThreadWasmTier2Generators() at shutdown to deal with the leftover tier 2 generators [5]. If all generators are being diverted, this code may cause shutdown issues, and the running tier 2 generators in the xpcom thread pool could potentially prevent shutdown. This may need to be addressed at HelperThreadPool::Shutdown() [6].

[1] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/src/vm/Runtime.cpp#75
[2] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/src/vm/HelperThreads.cpp#115
[3] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/src/vm/HelperThreads.cpp#2034
[4] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/xpconnect/src/XPCJSThreadPool.h#21
[5] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/src/vm/HelperThreads.cpp#189
[6] https://searchfox.org/mozilla-central/rev/1eb05019f47069172ba81a6c108a584a409a24ea/js/xpconnect/src/XPCJSRuntime.cpp#3387

Type: task → enhancement
Priority: -- → P2
Assignee: nobody → allstars.chh

The current plan is to switch over from using the internal pool to the external pool in one go, so I'm closing the bugs for individual task kinds.

No longer blocks: 1559660
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: