-
Notifications
You must be signed in to change notification settings - Fork 194
Commit baf286c
committed
lib: Add Double Helix Queue (DHQ) for cache-aware task migration
Implement Double Helix Queue (DHQ), a dual-strand priority queue designed
for LLC-aware task migration in multi-cache systems. DHQ maintains two
parallel strands (analogous to DNA's double helix) with coordinated access
to preserve cache affinity while enabling work-stealing.
Key features:
- Fixed-size implementation with pre-allocated capacity for use in
non-sleepable BPF contexts (enqueue/dispatch callbacks)
- Strand pairing constraint prevents unbounded imbalance between strands
- Three dequeue modes: Priority (lowest vtime), Alternating (fair), and
Balanced (load-aware)
- Both FIFO and VTime ordering modes within each strand
- Arena-based allocation for scalable concurrent access
DHQ advantages over single queues:
- Cache locality: Each strand maps to an LLC, preserving cache warmth
- Controlled migration: max_imbalance parameter limits cross-LLC movement
- Lower lock contention: Operations distributed across two strands
- Work conservation: Priority mode allows stealing while respecting affinity
- Prevents pathological cases where one LLC monopolizes migration queue
Implementation details:
- Backed by red-black trees (via scx_minheap) for O(log n) operations
- Strand constraint enforced at both enqueue and dequeue time
- Returns -EAGAIN when strand imbalance would be violated
- Returns -ENOSPC when capacity is reached
- Thread-safe via arena spinlocks
Files added:
- lib/dhq.bpf.c: Core DHQ implementation
- lib/DHQ_README.md: Comprehensive documentation with complexity analysis
- lib/selftests/st_dhq.bpf.c: Unit tests for DHQ operations
Designed for LLC migration, where:
- LLC pairs in same NUMA node share one DHQ
- Strand A = LLC 0 tasks (cache-warm to LLC 0)
- Strand B = LLC 1 tasks (cache-warm to LLC 1)
- Priority mode migrates highest-urgency tasks across LLCs
- max_imbalance controls migration rate
Signed-off-by: Daniel Hodges <[email protected]>1 parent 1f12ffd commit baf286cCopy full SHA for baf286c
File tree
Expand file treeCollapse file tree
7 files changed
+2184
-0
lines changedOpen diff view settings
Filter options
- lib
- selftests
- rust/scx_arena/selftests
Expand file treeCollapse file tree
7 files changed
+2184
-0
lines changedOpen diff view settings
0 commit comments