Divert WASM offthread compile tasks to use the XPCOM helper thread pool
Categories
(Core :: JavaScript Engine, enhancement, P2)
Tracking
()
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:
- 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. - 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. SinceThreadType
is exposed to HelperThreadPool through the RunnableTask interface, HelperThreadTaskHandler should be able to check for this if it needs to. 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
Reporter | ||
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 1•4 years ago
|
||
Comment 2•3 years ago
|
||
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.
Description
•