Update: modularisation of completion watermark together with a false-sharing alignment fix and batch updates. - #1550
Merged
ChaoZheng109 merged 1 commit intoJul 28, 2026
Conversation
…sharing alignment fix and batch updates. Signed-off-by: raphaelsteiner <raphael.steiner@huawei.com>
📝 WalkthroughWalkthroughCompletion flag reads and writes are centralized in ChangesCompletion flag and watermark flow
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ChaoZheng109
approved these changes
Jul 28, 2026
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.
This PR is the squashed version of #1536.
Summary
completion_flags[id & task_window_mask]load/store into two helpers onPTO2SharedMemoryRingHeader—is_completion_flag_set()/set_completion_flag()— and switches all 6 call sites (orchestrator, scheduler hot path, scheduler cold path) to use them instead.completed_watermarkCAS loop (advance by one slot, retry) withupdate_completed_watermark(), which scans the full contiguous completed prefix locally before issuing one CAS to jump the watermark forward by however many slots are ready — cutting the number of atomic RMW ops oncompleted_watermarkfrom O(advance distance) to O(contention events).alignas(64)totask_window_size, pushing the cold, read-mostly layout metadata onto its own cache line, separate from the hotcompleted_watermarkatomic that's CAS'd on every task completion — removes false sharing between the two.PTO2SharedMemoryRingHeaderlayoutstatic_assert(task_descriptors_offset: 160 → 216) to match; struct size stays 256 bytes.Why
completed_watermarkis CAS'd on the hot completion path for every task and previously shared a cache line with metadata read on nearly every fanin check, so each watermark bump invalidated that line for concurrent readers. Advancing it one slot at a time (instead of scanning the whole completed prefix) also meant up to N CAS attempts when several tasks completed in a burst.Testing
Ran
TestPagedAttention::Case2(a2a3 / tensormap_and_ringbuffer runtime) on NPU 3, 20 rounds each, from a clean build of both branches:Both branches pass golden comparison.
completion_watermarkis faster and meaningfully less jittery — consistent with fewer/cheaper atomic ops on the watermark and the removed false sharing.