Skip to content

wasm: make SMP acquire and release accesses atomic - #46

Merged
tombl merged 1 commit into
wasm-atomic-ticket-locksfrom
wasm-atomic-smp-accesses
Aug 9, 2026
Merged

wasm: make SMP acquire and release accesses atomic#46
tombl merged 1 commit into
wasm-atomic-ticket-locksfrom
wasm-atomic-smp-accesses

Conversation

@tombl

@tombl tombl commented Aug 8, 2026

Copy link
Copy Markdown
Owner

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.

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
tombl force-pushed the wasm-atomic-smp-accesses branch from e768dc5 to 10d0852 Compare August 8, 2026 16:01
@tombl
tombl merged commit 015960b into wasm Aug 9, 2026
1 check passed
@tombl
tombl deleted the wasm-atomic-smp-accesses branch August 9, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant