fix(compio-runtime): correct sched affinity mask on multi cores - #956
Merged
Conversation
YangchenYe323
force-pushed
the
fix/cpu-set-affinity
branch
from
June 19, 2026 02:16
03d3dbe to
0105b39
Compare
Member
|
Thanks! But compio is a single-threaded runtime. Why do you want to bind multiple cores? |
Contributor
Author
For example to pin a thread to a NUMA node like this pattern I found it's not always desirable to model everything "thread-per-core", for example, if I have a 1000 node cluste, every node has 128 cores, and runs an MPI style communication grid, naively doing the thread-per-core means every node will end up having 1000 * 128 connections to each other, which is not good. So I use a numa-aware thread pool to control that connection fanout |
Berrysoft
requested changes
Jun 21, 2026
Berrysoft
left a comment
Member
There was a problem hiding this comment.
Also consider using pthread_setaffinity_np for NetBSD? core_affinity also uses it.
YangchenYe323
force-pushed
the
fix/cpu-set-affinity
branch
7 times, most recently
from
June 21, 2026 16:56
b2318ce to
a866388
Compare
YangchenYe323
force-pushed
the
fix/cpu-set-affinity
branch
from
June 21, 2026 17:04
a866388 to
42bd379
Compare
Berrysoft
approved these changes
Jun 21, 2026
Merged
Open
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current implementation of
bind_to_cpu_setis incorrect because the underlying syscalls called bycore_affinity::set_for_current(sched_setaffinity) replaces the entire affinity mask, so passing in more than 1 cores results in the thread pinned to the last core instead of the whole set. I'm not sure core_affinity crate is still maintained (last update 8 years and author no activity since 2024), so I implemented the logic in compio directly.Disclaimer that claude wrote the code and it's not tested on non-Linux platforms, but I cross-referenced the code in core_affinity crate.