-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Count processors via affinity mask on linux #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for all this! This is impressive!
I just have some questions left in comments.
src/lib.rs
Outdated
} | ||
|
||
#[cfg(target_os = "linux")] | ||
fn get_num_cpus() -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether using affinity by default is better, or if it'd be a sort of breaking change. Would one always always want the affinity, or could one conceivably want to just know the number or CPUs on the machine anyways?
Put another way, should this be a separate function, or just be the default and only implementation for linux? I'm not saying one or the other is correct, I'd be interested in rationale for either case.
src/lib.rs
Outdated
target_os = "fuchsia", | ||
) | ||
#[cfg(feature = "nightly")] | ||
#[feature(asm, naked_functions)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there large benefits to using this asm as opposed to not requiring unstable features and using the bit masking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function exists in the standard library: https://doc.rust-lang.org/std/primitive.u64.html#method.count_ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just taken from my perfromance sensitive code written in C.
count_ones
is just what I wanted, thanks!
I've moved the question out of the line comment, so that edits don't make it disappear:
|
** updated ** I researched some other language implementations on Linux. Counts via affinity maskgolang
nproc(1)
Ruby
Counts by sysconf(_SC_NPROCESSORS_ONLN)D
Bothpython
|
I'm slightly inclined to follow golang, but welcome other opinions. I also wonder if that's breaking change (or a "bug fix"). |
My current feelings are:
So, I'm considering merging this as-is, unless there's other thoughts. |
@seanmonstar I agree that the default behavior should give you a reasonable number of threads to spawn. I'm not sure about whether it's a breaking change or not, but I'd say it should get a major bump. |
@seanmonstar the reason for
To do this what we're missing is the |
Thanks @kubo39! Excellent work! |
This Fixes #12