Skip to content

wasm: replace queued locks with atomic ticket locks - #45

Merged
tombl merged 1 commit into
wasmfrom
wasm-atomic-ticket-locks
Aug 9, 2026
Merged

wasm: replace queued locks with atomic ticket locks#45
tombl merged 1 commit into
wasmfrom
wasm-atomic-ticket-locks

Conversation

@tombl

@tombl tombl commented Aug 8, 2026

Copy link
Copy Markdown
Owner

The generic queued spinlock relies on coherent mixed-width atomic accesses. WebAssembly only orders atomic accesses to identical byte ranges, while the current unlock and slow paths emit plain byte and halfword stores overlapping 32-bit atomic RMWs.

Use architecture-owned FIFO ticket spinlocks and writer-ticket rwlocks instead. Each concurrently accessed field occupies its own u32 and every access uses a WebAssembly atomic operation. Contended waiters sleep on the changing field and are notified directly on handoff.

This removes the unsupported mixed-width access pattern while preserving FIFO progress for spinlock and writer acquisition.

The generic queued spinlock relies on coherent mixed-width atomic accesses. WebAssembly only orders atomic accesses to identical byte ranges, while the current unlock and slow paths emit plain byte and halfword stores overlapping 32-bit atomic RMWs.

Use architecture-owned FIFO ticket spinlocks and writer-ticket rwlocks instead. Each concurrently accessed field occupies its own u32 and every access uses a WebAssembly atomic operation. Contended waiters sleep on the changing field and are notified directly on handoff.

This removes the unsupported mixed-width access pattern while preserving FIFO progress for spinlock and writer acquisition.

Validation:
- full Wasm kernel build
- wasm-objdump confirms lock state uses only i32.atomic load/RMW, memory.atomic.wait32, and memory.atomic.notify
- temporary four-CPU validation passed 40,000 contended spin acquisitions and 20,000 writer acquisitions with exact counters and no ownership or reader/writer overlap errors
- five-run lifecycle comparison showed no material boot-time regression (5.22 s mean versus 5.32 s for successful qspin baseline runs)

The intermittent workqueue RuntimeError is not claimed fixed here: one of 30 lock-only lifecycle attempts hit an uncaptured RuntimeError, while 20 immediately repeated sequential attempts were clean.

Agent-Session: codex:019fe115-244a-76c1-b716-b8af6827da00
@tombl
tombl merged commit 31757f6 into wasm Aug 9, 2026
1 check passed
@tombl
tombl deleted the wasm-atomic-ticket-locks 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