Multithreading support for lazy-jit#1166
Conversation
80da4a5 to
1b9dcbb
Compare
|
Thanks! I will take a look tomorrow. |
|
Woke this morning with a realisation that it's probably better to use a channel after all—still requires synchronisation to get a clone, but that clone can then be stored thread-local which will then use far less locking. |
4bc1872 to
00ccca8
Compare
|
Ran some tests with more threads and started hitting BAD_ACCESS errors... placing this in draft while I investigate. |
96425ef to
23c6b56
Compare
|
I think bytecodealliance/wasmtime#2786 is required for this to work. I need to implement bytecodealliance/wasmtime#2786 (comment) though before it can be merged. |
|
I removed my previous comments as I'm now encountering different variations... but yes, I'm sure you're right that that's the cause here. |
|
I extended your branch to implement deferred GOT updates in https://github.com/eggyal/wasmtime/tree/atomic_jit — and that did indeed fix the problem here... but unless Cranelift is to itself run multithreaded, there's no chance of the GOT being updated from multiple threads so I don't think there's any need for Or is the issue about ensuring atomic updates of multiple GOT entries, such as data objects and related functions, so that they're never witnessed in an inconsistent state? Not sure |
|
Data races are UB in Rust and LLVM. LLVM is for example allowed to write arbitrary values (say 42) before writing the final value. This would crash the jitted code. Data races are not UB in Cranelift. For this reason the rust code needs to use atomic stores to prevent UB, while the Cranelift side doesn't need to use atomic loads to prevent UB. At least on all architectures currently supported by Cranelift. By the way I think you will need to ensure that two simultaneous requests to compile the same function will result in only a single compilation. |
|
Instead of storing a |
Aha, got it. Thanks.
D'oh! Well caught.
I've used |
|
I force pushed it directly to my PR branch. |
256a892 to
c87ea65
Compare
|
Requires exposure of |
c87ea65 to
ad8b191
Compare
|
bytecodealliance/wasmtime#2786 has been merged. @eggyal can you please rebase this PR? |
ad8b191 to
5c78324
Compare
|
@bjorn3 Not sure whether you saw that I rebased this as requested, but pinging you just in case. |
|
Completely missed it. Thanks for the ping. |
|
Pushed a commit to test this feature. |
|
CI seems to be having some issues with installing wine for windows testing. Merging as I don't expect any failures from this CI job. |
…jorn3 Sync rustc_codegen_cranelift The main hightlight this sync is basic support for AArch64. Most things should work on Linux, but there does seem to be an ABI incompatibility causing proc-macros to crash, see https://github.com/bjorn3/rustc_codegen_cranelift/issues/1184. Thanks to `@afonso360` for implementing all Cranelift features that were necessary to compile for AArch64 using cg_clif. Also thanks to `@shamatar` for implementing the `llvm.x86.addcarry.64` and `llvm.x86.subborrow.64` llvm intrinsics used by num-bigint (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1178) and `@eggyal` for implementing multi-threading support for the lazy jit mode. (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1166) r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
…jorn3 Sync rustc_codegen_cranelift The main hightlight this sync is basic support for AArch64. Most things should work on Linux, but there does seem to be an ABI incompatibility causing proc-macros to crash, see https://github.com/bjorn3/rustc_codegen_cranelift/issues/1184. Thanks to ``@afonso360`` for implementing all Cranelift features that were necessary to compile for AArch64 using cg_clif. Also thanks to ``@shamatar`` for implementing the `llvm.x86.addcarry.64` and `llvm.x86.subborrow.64` llvm intrinsics used by num-bigint (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1178) and ``@eggyal`` for implementing multi-threading support for the lazy jit mode. (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1166) r? ``@ghost`` ``@rustbot`` label +A-codegen +A-cranelift +T-compiler
…jorn3 Sync rustc_codegen_cranelift The main hightlight this sync is basic support for AArch64. Most things should work on Linux, but there does seem to be an ABI incompatibility causing proc-macros to crash, see https://github.com/bjorn3/rustc_codegen_cranelift/issues/1184. Thanks to ```@afonso360``` for implementing all Cranelift features that were necessary to compile for AArch64 using cg_clif. Also thanks to ```@shamatar``` for implementing the `llvm.x86.addcarry.64` and `llvm.x86.subborrow.64` llvm intrinsics used by num-bigint (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1178) and ```@eggyal``` for implementing multi-threading support for the lazy jit mode. (https://github.com/bjorn3/rustc_codegen_cranelift/pull/1166) r? ```@ghost``` ```@rustbot``` label +A-codegen +A-cranelift +T-compiler
Fixes #1124, in which @bjorn3 commented:
The problem I had using a channel was that I couldn't get the
Senderto the child threads other than through using a global static (in some way), which requires synchronisation... and then the channel just added additional synchronisation on top—which by that point was superfluous. This PR uses aMutex<VecDeque>for message passing instead.