-
Notifications
You must be signed in to change notification settings - Fork 198
scx_p2dq: Add DHQ support #3035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f611110 to
ea228ea
Compare
|
Performance tests using
|
05388d2 to
667b6e4
Compare
multics69
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I like the idea of DHQ.
In my understanding, the key idea is to pair two LLC domains for first-level load balancing (under the abstraction of DHQ), so that cache affinity is preserved within the pair.
One minor suggestion is that dhq.h should be included in the first commit rather than the second.
|
Can we add the README to a separate directory, e.g., docs/ ? |
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 <hodgesd@meta.com>
Integrate Double Helix Queue (DHQ) as an alternative to ATQ for LLC-aware task migration, and fix critical race condition causing migration-disabled task errors. DHQ Integration: - Add --dhq-enabled flag to enable DHQ mode for LLC migration - Add --dhq-max-imbalance parameter (default: 3) to control strand balance - Create one DHQ per pair of LLCs in same NUMA node - Map each LLC to a specific strand (A or B) for cache affinity - Each CPU inherits strand from its LLC for proper load distribution - DHQ provides cache-aware migration with controlled cross-LLC movement Strand-Specific DHQ Operations: Use scx_dhq_peek_strand() and scx_dhq_pop_strand() instead of generic operations to ensure CPUs only consume from their designated strand. This preserves cache locality and prevents load imbalance. Data Structure Changes: - Add mig_dhq and dhq_strand to cpu_ctx and llc_ctx - Add llc_pair_dhqs[] for shared DHQs between LLC pairs - Add llcs_per_node[] to track LLCs per NUMA node - Add P2DQ_ENQUEUE_PROMISE_DHQ_VTIME enqueue promise type - Add enqueue_promise_dhq struct for DHQ-specific metadata Configuration: - p2dq_config.dhq_enabled: Enable DHQ mode - p2dq_config.dhq_max_imbalance: Control strand pairing (0 = unlimited) - Priority mode: lowest vtime wins across strands Build System: - Add lib/dhq.bpf.c to scx_p2dq and scx_chaos builds scx_chaos Compatibility: - Update enqueue promise handling to recognize DHQ type - Error message updated to mention both ATQs and DHQs not supported Benefits: - Cache affinity: Tasks stay on origin LLC (strand) - Controlled migration: max_imbalance prevents migration storms - Race-free: Atomic affinity handling eliminates migration-disabled errors - Work conservation: Cross-strand stealing when priority demands - Scalable: Lock contention distributed across DHQ strands Signed-off-by: Daniel Hodges <hodgesd@meta.com>
scx_p2dq: Add DHQ support and fix migration-disabled task errors
Integrate Double Helix Queue (DHQ) as an alternative to ATQ for LLC-aware task migration.
DHQ Integration:
Strand-Specific DHQ Operations:
Use scx_dhq_peek_strand() and scx_dhq_pop_strand() instead of generic operations to ensure CPUs only consume from their designated strand. This preserves cache locality and prevents load imbalance.
Data Structure Changes:
Configuration:
Build System:
scx_chaos Compatibility:
Benefits:
Signed-off-by: Daniel Hodges hodgesd@meta.com