wasm: replace queued locks with atomic ticket locks - #45
Merged
Conversation
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
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 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.