-
Notifications
You must be signed in to change notification settings - Fork 59
feat(runtime): implement thread affinity for runtime and dispatcher #445
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
Merged
Berrysoft
merged 10 commits into
compio-rs:master
from
numinnex:runtime_dispatcher_thread_affinity
Jul 6, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3bd62b6
feat(runtime): implement thread affinity for runtime and dispatcher
numinnex cd0aa6c
cargo fmt
numinnex a23e9dd
replace nix with core_affinity
numinnex d2d55f4
simplify ifdefs
numinnex 513696c
feat(runtime): change the thread affinity method in dispatcher
numinnex e01a89f
feat(runtime): implement bind_to_cpu_set method
numinnex 2efe07b
feat(runtime): change cpu_set from vec to hashset
numinnex c6f85ab
fix(runtime): revert signature of RuntimeBuilder
Berrysoft 89f6b87
fix(runtime): remove build.rs
Berrysoft fe61da7
fix(runtime): make clippy happy
Berrysoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
use std::collections::HashSet; | ||
|
||
use compio_log::*; | ||
use core_affinity::CoreId; | ||
|
||
/// Bind current thread to given cpus | ||
pub fn bind_to_cpu_set(cpus: &HashSet<usize>) { | ||
if cpus.is_empty() { | ||
return; | ||
} | ||
|
||
let Some(ids) = core_affinity::get_core_ids() else { | ||
return; | ||
}; | ||
|
||
let ids = ids | ||
.into_iter() | ||
.map(|core_id| core_id.id) | ||
.collect::<HashSet<_>>(); | ||
match (ids.iter().max(), cpus.iter().max()) { | ||
(Some(max_id), Some(max_cpu)) if *max_cpu > *max_id => { | ||
error!("CPU ID: {max_cpu} exceeds maximum available CPU ID: {max_id}"); | ||
} | ||
_ => {} | ||
} | ||
let cpu_set = ids.intersection(cpus); | ||
for cpu in cpu_set { | ||
let result = core_affinity::set_for_current(CoreId { id: *cpu }); | ||
if !result { | ||
warn!("cannot set CPU {cpu} for current thread"); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.