Skip to content

Use os.sched_getaffinity for parallelism - #9132

Merged
tlively merged 2 commits into
mainfrom
sched-getaffinity-cpu-count
Sep 22, 2026
Merged

tlively merged 2 commits into
mainfrom
sched-getaffinity-cpu-count

Conversation

@tlively

@tlively tlively commented Sep 21, 2026

Copy link
Copy Markdown
Member

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.

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
tlively requested a review from a team as a code owner September 21, 2026 23:06
@tlively
tlively requested review from aheejin and sbc100 and removed request for a team September 21, 2026 23:06

@sbc100 sbc100 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.

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.

@sbc100

sbc100 commented Sep 21, 2026

Copy link
Copy Markdown
Member

@tlively

tlively commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

Done. Adapted it with some tweaks: inlining get_env_int, using BINARYEN_CORES (which is already used elsewhere), and formatting.

@tlively
tlively enabled auto-merge (squash) September 21, 2026 23:51
Comment thread scripts/monitor_fuzz.py
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

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.

Surely get_num_cores should never return zero / None? Maybe just assert cores instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's probably fine, but this idiom is apparently a best practice and it seems harmless enough.

@tlively
tlively disabled auto-merge September 21, 2026 23:53
@tlively
tlively enabled auto-merge (squash) September 21, 2026 23:57
@tlively
tlively merged commit 336baa3 into main Sep 22, 2026
16 checks passed
@tlively
tlively deleted the sched-getaffinity-cpu-count branch September 22, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants