forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Performance] Refactor ThreadManager, and use it in some places. (apt…
- Loading branch information
Showing
23 changed files
with
279 additions
and
291 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[cfg(target_os = "linux")] | ||
use libc::{cpu_set_t, sched_setaffinity}; | ||
|
||
#[cfg(target_os = "linux")] | ||
pub(crate) fn new_cpu_set() -> cpu_set_t { | ||
unsafe { std::mem::zeroed::<cpu_set_t>() } | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub(crate) fn pin_cpu_set(cpu_set: cpu_set_t) -> impl Fn() + Send + Sync + 'static { | ||
move || { | ||
unsafe { | ||
sched_setaffinity( | ||
0, // Defaults to current thread | ||
std::mem::size_of::<cpu_set_t>(), | ||
&cpu_set, | ||
); | ||
}; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
mod common; | ||
pub(crate) mod strategies; | ||
pub mod thread_manager; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::thread_manager::ThreadManager; | ||
use aptos_runtimes::spawn_rayon_thread_pool; | ||
use rayon::ThreadPool; | ||
|
||
pub struct DefaultThreadManager { | ||
exe_threads: ThreadPool, | ||
non_exe_threads: ThreadPool, | ||
io_threads: ThreadPool, | ||
} | ||
|
||
impl DefaultThreadManager { | ||
pub(crate) fn new() -> DefaultThreadManager { | ||
let exe_threads = spawn_rayon_thread_pool("exe".into(), Some(num_cpus::get())); | ||
let non_exe_threads = spawn_rayon_thread_pool("non_exe".into(), Some(num_cpus::get())); | ||
let io_threads = spawn_rayon_thread_pool("io".into(), Some(64)); | ||
Self { | ||
exe_threads, | ||
non_exe_threads, | ||
io_threads, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> ThreadManager<'a> for DefaultThreadManager { | ||
fn get_exe_cpu_pool(&'a self) -> &'a ThreadPool { | ||
&self.exe_threads | ||
} | ||
|
||
fn get_non_exe_cpu_pool(&'a self) -> &'a ThreadPool { | ||
&self.non_exe_threads | ||
} | ||
|
||
fn get_io_pool(&'a self) -> &'a ThreadPool { | ||
&self.io_threads | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub(crate) mod default; | ||
#[cfg(target_os = "linux")] | ||
pub(crate) mod pin_exe_threads_to_cores; |
70 changes: 70 additions & 0 deletions
70
experimental/runtimes/src/strategies/pin_exe_threads_to_cores.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{ | ||
common::{new_cpu_set, pin_cpu_set}, | ||
thread_manager::ThreadManager, | ||
}; | ||
use aptos_runtimes::spawn_rayon_thread_pool_with_start_hook; | ||
use libc::CPU_SET; | ||
use rayon::ThreadPool; | ||
|
||
pub(crate) struct PinExeThreadsToCoresThreadManager { | ||
exe_threads: ThreadPool, | ||
non_exe_threads: ThreadPool, | ||
io_threads: ThreadPool, | ||
} | ||
|
||
impl PinExeThreadsToCoresThreadManager { | ||
pub(crate) fn new(num_exe_cpu: usize) -> Self { | ||
let core_ids = core_affinity::get_core_ids().unwrap(); | ||
assert!(core_ids.len() > num_exe_cpu); | ||
|
||
let mut exe_cpu_set = new_cpu_set(); | ||
let mut non_exe_cpu_set = new_cpu_set(); | ||
for core_id in core_ids.iter().take(num_exe_cpu) { | ||
unsafe { CPU_SET(core_id.id, &mut exe_cpu_set) }; | ||
} | ||
for core_id in core_ids.iter().skip(num_exe_cpu) { | ||
unsafe { CPU_SET(core_id.id, &mut non_exe_cpu_set) }; | ||
} | ||
|
||
let exe_threads = spawn_rayon_thread_pool_with_start_hook( | ||
"exe".into(), | ||
Some(num_exe_cpu), | ||
pin_cpu_set(exe_cpu_set), | ||
); | ||
|
||
let non_exe_threads = spawn_rayon_thread_pool_with_start_hook( | ||
"non_exe".into(), | ||
Some(core_ids.len() - num_exe_cpu), | ||
pin_cpu_set(non_exe_cpu_set), | ||
); | ||
|
||
let io_threads = spawn_rayon_thread_pool_with_start_hook( | ||
"io".into(), | ||
Some(64), | ||
pin_cpu_set(non_exe_cpu_set), | ||
); | ||
|
||
Self { | ||
exe_threads, | ||
non_exe_threads, | ||
io_threads, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> ThreadManager<'a> for PinExeThreadsToCoresThreadManager { | ||
fn get_exe_cpu_pool(&'a self) -> &'a ThreadPool { | ||
&self.exe_threads | ||
} | ||
|
||
fn get_non_exe_cpu_pool(&'a self) -> &'a ThreadPool { | ||
&self.non_exe_threads | ||
} | ||
|
||
fn get_io_pool(&'a self) -> &'a ThreadPool { | ||
&self.io_threads | ||
} | ||
} |
Oops, something went wrong.