-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
windows: provide more accurate result for available_parallelism if cores > 64 #114856
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
Anyone with > 64 cores test please? |
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.
Do the docs also need updating with Windows specific information?
This comment has been minimized.
This comment has been minimized.
https://doc.rust-lang.org/nightly/std/thread/fn.available_parallelism.html
|
This comment has been minimized.
This comment has been minimized.
The Miri subtree was changed cc @rust-lang/miri |
"GetActiveProcessorCount" => { | ||
let [groupnumber] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; | ||
this.read_scalar(groupnumber)?.to_u16()?; | ||
this.write_scalar(Scalar::from_u32(this.machine.num_cpus), dest)?; | ||
} |
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 probably wrong, need advice.
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.
cc @rust-lang/miri
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.
We were already summoned by rustbot automatically :)
Why do you think this is wrong?
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 should be further up the match, down here is the section for if this.frame_in_std()
shims. Probably putting it with GetSystemInfo makes sense.
Other than that -- without knowing GetActiveProcessorCount, this seems reasonable? A brief comment explaining why we can ignore the groupnumber might be good.
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.
Moved and added comment.
This comment has been minimized.
This comment has been minimized.
Uhh, can't this be more human-friendly message? |
Given that Windows 11 appears to lift the 64-CPU limitation by default without requiring any special handling from a process, this seems reasonable. r=me once CI passes, and once someone from miri signs off on the miri changes. |
@rustbot author |
Yeah we're working on that. Or at least I hope this has the side-effect of making things better. I don't know why it uses JSON, it is some strange interaction of |
@@ -3875,47 +3875,6 @@ pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: SYMBOLIC_LINK_FLAGS = 2u | |||
pub const SYMBOLIC_LINK_FLAG_DIRECTORY: SYMBOLIC_LINK_FLAGS = 1u32; | |||
pub const SYMLINK_FLAG_RELATIVE: u32 = 1u32; | |||
pub const SYNCHRONIZE: FILE_ACCESS_RIGHTS = 1048576u32; | |||
#[repr(C)] | |||
pub struct SYSTEM_INFO { |
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.
Miri was relying on this type declaration for its GetSystemInfo
shim, that's why we are getting ICEs now.
The alternative is to change Miri's GetSystemInfo
to use hard-coded offsets for the two fields it cares about (dwPageSize
, dwNumberOfProcessors
).
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 think it's ok to keep the old definitions around even though they're no longer used by std. I don't think there's yet a pressing need to keep windows_sys.rs
definitions strictly minimal,. Plus keeping them reduces churn should we decide to use them for something else in the future.
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 can also disentangle Miri from that definition, if you'd prefer us not to rely on it. That can happen asynchronously with this PR, so eventually when the Miri patch lands you can do the cleanup.
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 mean, it might be better overall if miri wasn't entangled with the std this way but I don't feel particularly strongly about it.
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.
On Unix we rely on libc
for tons of constants and types. That's just a lot more maintainable than hard-coding them all in the Miri sources. For Windows sadly there is no libc
-equivalent (that is present in the sysroot) so we can only use the few things we can find in std...
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.
Can you not use the windows-sys
crate directly? The definitions in std are essentially just a vendored version of it.
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.
We need a crate that's in the sysroot. (Miri might be running a Windows target on a Linux host.) So... we can do that once std depends on it. ;)
Yes, this should be updated if that restriction is lifted. Based on #114856 (comment) it should now mention that may be overreporting on windows 10 because processes won't use more than 64 cores by default. |
// Number of cores, but more accurate vaulue, than GetSystemInfo.dwNumberOfProcessors | ||
// if number of cores > 64. If called with ALL_PROCESSOR_GROUPS as groupnumber, | ||
// returns total number of cores, instead of number in group, see | ||
// https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getactiveprocessorcount |
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 sounds like we should do throw_unsup_format!
if the groupnumber is not ALL_PROCESSOR_GROUPS, since we are not correctly handling that case.
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.
vaulue
typo.
let mut sysinfo: c::SYSTEM_INFO = crate::mem::zeroed(); | ||
c::GetSystemInfo(&mut sysinfo); | ||
sysinfo.dwNumberOfProcessors as usize | ||
// FIXME: windows::Win32::System::SystemServices::ALL_PROCESSOR_GROUPS should be u16, not u32 |
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.
microsoft/win32metadata@8f70180
will be changed to Windows.Win32.System.Threading.Apis.ALL_PROCESSOR_GROUPS
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.
Hm... I've been thinking about this some more. Could you move the correct definition of ALL_PROCESSOR_GROUPS
into c.rs
? That way we can keep all the FIXME
s into one file so they're easier to find and fix when the bindings are next updated. Otherwise it might be easier to forget about it.
@klensy FYI: when a PR is ready for review, send a message containing |
☔ The latest upstream changes (presumably #118232) made this pull request unmergeable. Please resolve the merge conflicts. |
@klensy @rustbot label: +S-inactive |
This should give more accurate result if number of cores > 64
see:
https://devblogs.microsoft.com/oldnewthing/20200824-00/?p=104116
ninja-build/ninja#1604
Could probably implement using GetLogicalProcessorInformationEx
see: ninja-build/ninja#1674
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getactiveprocessorcount >= Win 7
crates that probably want to fix it too:
sysinfo
: but maybeGetLogicalProcessorInformationEx
instead?num_cpus
: obviously