Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
enhanced_work_stealing_config.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
16
17#include <chrono>
18#include <cstddef>
19
20namespace kcenon::thread
21{
22
54{
55 // ========================================================================
56 // Enable/Disable
57 // ========================================================================
58
60 bool enabled = false;
61
62 // ========================================================================
63 // Victim Selection Policy
64 // ========================================================================
65
68
69 // ========================================================================
70 // NUMA Configuration
71 // ========================================================================
72
74 bool numa_aware = false;
75
78 double numa_penalty_factor = 2.0;
79
81 bool prefer_same_node = true;
82
83 // ========================================================================
84 // Batch Stealing Configuration
85 // ========================================================================
86
88 std::size_t min_steal_batch = 1;
89
91 std::size_t max_steal_batch = 4;
92
95
96 // ========================================================================
97 // Steal Attempts Configuration
98 // ========================================================================
99
101 std::size_t max_steal_attempts = 3;
102
104 std::size_t max_consecutive_failures = 10;
105
106 // ========================================================================
107 // Backoff Configuration
108 // ========================================================================
109
112
114 std::chrono::microseconds initial_backoff{50};
115
117 std::chrono::microseconds max_backoff{1000};
118
120 double backoff_multiplier = 2.0;
121
122 // ========================================================================
123 // Locality Tracking
124 // ========================================================================
125
127 bool track_locality = false;
128
130 std::size_t locality_history_size = 16;
131
132 // ========================================================================
133 // Statistics Collection
134 // ========================================================================
135
137 bool collect_statistics = false;
138
139 // ========================================================================
140 // Factory Methods
141 // ========================================================================
142
151
157 {
159 config.enabled = true;
161 config.numa_aware = true;
162 config.prefer_same_node = true;
163 config.numa_penalty_factor = 2.0;
164 config.collect_statistics = true;
165 return config;
166 }
167
173 {
175 config.enabled = true;
177 config.track_locality = true;
178 config.locality_history_size = 32;
179 config.collect_statistics = true;
180 return config;
181 }
182
188 {
190 config.enabled = true;
192 config.min_steal_batch = 2;
193 config.max_steal_batch = 8;
194 config.adaptive_batch_size = true;
195 return config;
196 }
197
203 {
205 config.enabled = true;
207 config.numa_aware = true;
208 config.prefer_same_node = true;
209 config.numa_penalty_factor = 3.0;
210 config.track_locality = true;
211 config.collect_statistics = true;
212 return config;
213 }
214};
215
216} // namespace kcenon::thread
Enhanced policies for selecting work-stealing victims.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
steal_backoff_strategy
Backoff strategies for work-stealing operations.
@ exponential
Exponential increase: delay = initial * 2^attempt.
enhanced_steal_policy
Enhanced policies for selecting work-stealing victims.
@ hierarchical
NUMA node first, then random within node (large NUMA systems)
@ locality_aware
Prefer workers with recent cooperation history (cache affinity)
@ adaptive
Select based on queue sizes (best for uneven loads)
@ numa_aware
Prefer workers on the same NUMA node (reduces cross-node traffic)
Backoff strategies for work-stealing operations.
Configuration for enhanced work-stealing with NUMA awareness.
std::chrono::microseconds max_backoff
Maximum backoff delay cap (default: 1000 microseconds)
static auto hierarchical_numa() -> enhanced_work_stealing_config
Create a configuration for hierarchical NUMA systems.
std::size_t max_steal_batch
Maximum number of jobs to steal in a batch (default: 4)
bool track_locality
Enable work affinity tracking between workers (default: disabled)
std::size_t max_steal_attempts
Maximum number of steal attempts per round (default: 3)
steal_backoff_strategy backoff_strategy
Backoff strategy between failed steal attempts (default: exponential)
static auto batch_optimized() -> enhanced_work_stealing_config
Create a configuration for aggressive batch stealing.
std::size_t min_steal_batch
Minimum number of jobs to steal in a batch (default: 1)
bool collect_statistics
Enable statistics collection (default: disabled)
static auto default_config() -> enhanced_work_stealing_config
Create a default configuration (disabled)
std::chrono::microseconds initial_backoff
Initial backoff delay (default: 50 microseconds)
bool numa_aware
Enable NUMA-aware stealing (default: disabled)
static auto numa_optimized() -> enhanced_work_stealing_config
Create a configuration optimized for NUMA systems.
double backoff_multiplier
Backoff multiplier for exponential strategy (default: 2.0)
static auto locality_optimized() -> enhanced_work_stealing_config
Create a configuration optimized for cache locality.
bool enabled
Master switch for work-stealing (default: disabled)
std::size_t max_consecutive_failures
Maximum consecutive failures before yielding (default: 10)
std::size_t locality_history_size
Size of cooperation history for locality tracking (default: 16)
enhanced_steal_policy policy
Policy for selecting steal victims (default: adaptive)
double numa_penalty_factor
Cost multiplier for cross-NUMA node steals (default: 2.0) Higher values make cross-node steals less l...
bool adaptive_batch_size
Dynamically adjust batch size based on victim's queue depth (default: true)
bool prefer_same_node
Prefer workers on the same NUMA node (default: true)