cpu pinning
This commit is contained in:
parent
fd0cd86a8d
commit
25fa558a17
|
@ -509,6 +509,8 @@ impl ThreadPool {
|
|||
return self.pool_state.num_threads.load(Ordering::Acquire);
|
||||
}
|
||||
|
||||
let cpus = core_affinity::get_core_ids().unwrap();
|
||||
|
||||
let _guard = self.pool_state.lock.lock();
|
||||
|
||||
let current_size = self.pool_state.num_threads.load(Ordering::Acquire);
|
||||
|
@ -528,7 +530,9 @@ impl ThreadPool {
|
|||
let new_threads = &self.threads[current_size..new_size];
|
||||
|
||||
for (i, _) in new_threads.iter().enumerate() {
|
||||
let core = cpus[i];
|
||||
std::thread::spawn(move || {
|
||||
core_affinity::set_for_current(core);
|
||||
WorkerThread::worker_loop(&self, current_size + i);
|
||||
});
|
||||
}
|
||||
|
@ -1317,7 +1321,7 @@ mod tests {
|
|||
|
||||
let now = std::time::Instant::now();
|
||||
run_in_scope(pool, |s| {
|
||||
for &p in core::iter::repeat_n(PRIMES, 0x1000).flatten() {
|
||||
for &p in core::iter::repeat_n(PRIMES, 0x200).flatten() {
|
||||
s.spawn(move |_| {
|
||||
// std::thread::sleep(Duration::from_micros(p as u64));
|
||||
// spin for
|
||||
|
|
Loading…
Reference in a new issue