Skip to content

fix(compio-runtime): correct sched affinity mask on multi cores - #956

Merged
Berrysoft merged 3 commits into
compio-rs:masterfrom
YangchenYe323:fix/cpu-set-affinity
Jun 21, 2026
Merged

fix(compio-runtime): correct sched affinity mask on multi cores#956
Berrysoft merged 3 commits into
compio-rs:masterfrom
YangchenYe323:fix/cpu-set-affinity

Conversation

@YangchenYe323

Copy link
Copy Markdown
Contributor

The current implementation of bind_to_cpu_set is incorrect because the underlying syscalls called by core_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.

@github-actions github-actions Bot added bug Something isn't working package: runtime Related to compio-runtime labels Jun 19, 2026
@YangchenYe323
YangchenYe323 force-pushed the fix/cpu-set-affinity branch from 03d3dbe to 0105b39 Compare June 19, 2026 02:16
@Berrysoft

Copy link
Copy Markdown
Member

Thanks! But compio is a single-threaded runtime. Why do you want to bind multiple cores?

@YangchenYe323

Copy link
Copy Markdown
Contributor Author

Thanks! But compio is a single-threaded runtime. Why do you want to bind multiple cores?

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 Berrysoft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider using pthread_setaffinity_np for NetBSD? core_affinity also uses it.

Comment thread compio-runtime/Cargo.toml Outdated
@YangchenYe323
YangchenYe323 force-pushed the fix/cpu-set-affinity branch 7 times, most recently from b2318ce to a866388 Compare June 21, 2026 16:56
@YangchenYe323
YangchenYe323 force-pushed the fix/cpu-set-affinity branch from a866388 to 42bd379 Compare June 21, 2026 17:04
@YangchenYe323
YangchenYe323 requested a review from Berrysoft June 21, 2026 17:10
@Berrysoft
Berrysoft merged commit aa6cc46 into compio-rs:master Jun 21, 2026
144 of 145 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 21, 2026
@github-actions github-actions Bot mentioned this pull request Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working package: runtime Related to compio-runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants