wasm: make SMP acquire and release accesses atomic - #46
Merged
Conversation
The generic SMP acquire/release helpers implement ordering as a fence around READ_ONCE or WRITE_ONCE. In WebAssembly shared memory those remain non-atomic accesses, so they do not form the atomic reads-from relationship needed to synchronize threads. Override release stores, acquire loads, and conditional loads with __atomic builtins. WebAssembly currently lowers all of these to sequentially consistent atomic instructions. Tell Clang that fields in packed containers retain the natural alignment required by these operations so it emits inline Wasm atomics rather than unsupported library calls. This also replaces many fence-plus-plain-access sequences with one atomic access at the actual synchronization location. In the built kernel, atomic loads increase from 2,088 to 2,850, atomic stores from 420 to 912, and fences fall from 3,134 to 1,900. finish_task_switch(), for example, changes from atomic.fence plus i32.store to i32.atomic.store. Validation: - full Wasm kernel build, including packed objpool release/acquire sites - checkpatch: no errors or warnings - 30/30 four-CPU lifecycle stress runs reached the intended panic with no RuntimeError or timeout - temporary four-CPU lock validation passed with exact counters and no exclusion errors - five-run lifecycle comparison showed no material boot-time regression (5.25 s mean versus 5.32 s for successful baseline runs) Agent-Session: codex:019fe115-244a-76c1-b716-b8af6827da00
tombl
force-pushed
the
wasm-atomic-smp-accesses
branch
from
August 8, 2026 16:01
e768dc5 to
10d0852
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generic SMP acquire/release helpers implement ordering as a fence around READ_ONCE or WRITE_ONCE. In WebAssembly shared memory those remain non-atomic accesses, so they do not form the atomic reads-from relationship needed to synchronize threads.
Override release stores, acquire loads, and conditional loads with __atomic builtins. WebAssembly currently lowers all of these to sequentially consistent atomic instructions. Tell Clang that fields in packed containers retain the natural alignment required by these operations so it emits inline Wasm atomics rather than unsupported library calls.
This also replaces many fence-plus-plain-access sequences with one atomic access at the actual synchronization location. In the built kernel, atomic loads increase from 2,088 to 2,850, atomic stores from 420 to 912, and fences fall from 3,134 to 1,900. finish_task_switch(), for example, changes from atomic.fence plus i32.store to i32.atomic.store.