Use os.sched_getaffinity for parallelism - #9132
Merged
Merged
Conversation
On linux, os.sched_getaffinity(0) reports the number of cores available to the current process. Using it instead of raw os.cpu_count() will have better results when used in conjunction with e.g. `taskset` to limit parallel fuzzing or testing to a subset of the machine's cores.
tlively
requested review from
aheejin and
sbc100
and removed request for
a team
September 21, 2026 23:06
sbc100
approved these changes
Sep 21, 2026
sbc100
left a comment
Member
There was a problem hiding this comment.
Nice!
We are currently on python 3.10 minimum, and since this code is only used for testing perhaps we can soon update that to 3.13.
Member
|
Actually do you want to just copy the emscripten version: |
Member
Author
|
Done. Adapted it with some tweaks: inlining |
tlively
enabled auto-merge (squash)
September 21, 2026 23:51
sbc100
approved these changes
Sep 21, 2026
sbc100
reviewed
Sep 21, 2026
| os.path.dirname(os.path.abspath(__file__))) | ||
| default_log_dir = os.path.join(binaryen_root, 'out', 'test') | ||
| cores = os.cpu_count() or 1 | ||
| cores = get_num_cores() or 1 |
Member
There was a problem hiding this comment.
Surely get_num_cores should never return zero / None? Maybe just assert cores instead?
Member
Author
There was a problem hiding this comment.
That's probably fine, but this idiom is apparently a best practice and it seems harmless enough.
tlively
disabled auto-merge
September 21, 2026 23:53
tlively
enabled auto-merge (squash)
September 21, 2026 23:57
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.
On linux, os.sched_getaffinity(0) reports the number of cores available to the current process. Using it instead of raw os.cpu_count() will have better results when used in conjunction with e.g.
tasksetto limit parallel fuzzing or testing to a subset of the machine's cores.