-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for core::arch::{x86, x86_64}::has_cpuid #60123
Comments
@rfcbot fcp merge There's a longer description of what's being stablilized on the PR, so looking for an official sign-off now! |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns: Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
In what circumstance would somebody call The original RFC mentioned me as somebody who might be interested in this, but really what I'm interested in is the actual CPUID and related intrinsics. |
Yes. SGX target is notable modern target which does not support CPUID. |
Right. However, in practice we need to know "Is this SGX?" not just vaguely "Is CPUID available?" In particular, if the target is SGX then we'll assume certain features are available that we wouldn't normally assume are available by default otherwise. FWIW, I have code that uses CPUID extensively on all non-SGX x86 and amd64 targets, but I still don't have any use for this function, AFAICT, because it doesn't provide information useful to make a decision. (I mention this because I was mentioned in the other RFC that motivated this.) |
Heh, I wonder what result the On a similar note, if you are calling |
Registering Brian's point above in #60123 (comment). Do we know of someone with a use case that benefits from this function? How did it come to be added originally?
@rfcbot concern not useful |
@alexcrichton Please cancel the FCP and include T-Lang. (I've noted this on many occasions -- exposing intrinsics adds new fundamental abilities that cannot be done in Rust code otherwise and all such decisions needs T-Lang approval) |
When you want to know whether the hardware you are running on has the
Many. CPUID was introduced with the Pentium and i486-SL architectures, and Rust does support both i486 and i386 targets - we even ship some i386 targets with
Lucky you I guess. As the mini-RFC mentions, all mainstream compilers do CPUID detection in their CPUID intrinsics. i386 and i486 are modern enough that all modern toolchains can support it without many issues, but old enough to predate the introduction of the CPUID instruction.
On SGX doing x86_64 hardware feature detection via the CPUID instruction is not something you can do. Still,
|
Wait, this is wrong, the current implementation does properly support SGX and it does the obvious thing that was suggested above already: https://github.com/rust-lang-nursery/stdsimd/blob/master/crates/core_arch/src/x86/cpuid.rs#L87 |
The motivation for this intrinsic is still unclear to me. Specifically, for SGX, feature detection might work when using |
I've commented on that issue, since I think the claim is not 100% precise, but puting us back on topic: implementing run-time feature detection for SGX is orthogonal from being able to tell whether a CPU supports the CPUID instruction or not. For SGX,
If your application is |
OK, then what we really need to know is why CPUID isn't available: because the target is too old, or because SGX, because the toolchain has been configured to recommend/require only static compile-time feature detection, or for some other reason. |
If you need to know any of that (where one of the things you mention can’t
happen, and two are the same, so there are only two cases) has_cpuid is one
of the building blocks you can use to query that. But the std cpuid APIs
are unsafe, and std only needs to know whether they are safe to call.
…On Sun 21. Apr 2019 at 04:01, Brian Smith ***@***.***> wrote:
Rust does support both i486 and i386 targets - we even ship some i386
targets with rustup like i386-apple-ios although more are available via cargo
xbuild (e.g. i386 linux targets).
OK, then what we really need to know is why CPUID isn't available: because
the target is too old, or because SGX, because the toolchain has been
configured to recommend/require only static compile-time feature detection,
or for some other reason.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#60123 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAG43JW77ML7OKRDUDTDFNDPRPDI5ANCNFSM4HHHEDMQ>
.
|
What is the thing that can't, and will never, happen?
I can get all the same information without
I don't know what this means. If you're saying that the current implementation of libstd needs this for some reason, then libstd can already use it without it being stable. |
If you don't want to do run-time feature detection, you can just not use
You can run i386 binaries on skylake, which does have CPUID. What does knowing that the target is i386 and does not have CPUID tell you about the hardware the binary actually runs on ?
How can you tell whether the hardware an i386 or i486 binary runs on supports the CPUID instruction without |
OK, I didn't realize that this was doing runtime detection (using EFLAGS bit 21 to detect whether CPUID is available) vs. determining it statically. A few things I noticed:
The runtime detection is conditional on |
Iff this is the case with the current implementation, please fill a bug in rust-lang/rust about it since that would mean that the implementation of
Rust i686 targets do have SSE, what they don't have is SSE2. Doing better on i586 is possible (rust-lang/stdarch#497), PRs welcome. |
Can someone confirm that this is the entire intended target audience for this function, or are there other reasons someone might want to call it outside of 386 and 486? It's strange to me that the motivation in rust-lang/stdarch#730 refers to @briansmith but Brian won't need this function. I am still trying to work out whether anyone else would ever want to call this. How does this typically work in C++? The PR mentions that neither clang nor gcc expose this functionality. What do people do instead? If there is an implementation of has_cpuid available through crates.io, do we know of anyone calling it? |
Could you take a look at rust-lang/stdarch#730 and let me know whether you still would like T-lang involved? This isn't an intrinsic in the sense of |
As far as I can tell, the function is implemented using |
@rfcbot fcp cancel |
@dtolnay proposal cancelled. |
As briansmith has noted, you cannot do so without additional
It would be fine if we're willing to just do so. As far as I understand, I think we've avoided doing so out of a reluctance to include what is target-specific code in core.
The CPUID information, when accessed from userspace, constitutes a kind of special calling convention with the kernel, as the kernel is allowed to pick the answers. It is not exactly "raw", in that sense, unless accessed from the privileged context, where one is allowed to see the true answers (and change them). |
T-lang has already made some decisions re: target-features that implicitly relate to CPUID: #73631 (comment) |
cc @rust-lang/libs-api I am requesting that libs-api advance a new FCP to remove ...Note that key detail: it is never possible to simply invoke CPUID with impunity, due to the existence of if has_cpuid() {
// SAFETY: see previous line
let cpuid_result = unsafe { __cpuid(some_leaf) };
// the rest of the code may never be reached because of a fault,
// and our fate is decided by the platform's fault handlers
} I don't think a function that returns a One can make the argument that because these behaviors are relatively well-specified (for the CPUs that have CPUID, anyways), that this is "sound" nonetheless, because if cpu_chosen() {
jump_to(cpu_specific_code)
} else if os_chosen() {
jump_to(os_specific_code)
} else {
let eax, ebx, ecx, edx;
asm!(..);
CpuidResult { eax, ebx, ecx, edx }
} But if we are arguing that, then we should just have the courage to make Let us render unto |
You usually cannot rely on what CPUID reports when you are operating in a kernel context or in other special contexts (probably signal handlers). This, combined with the SGX and i586 complexity, is why I suggested that this be made a target feature. |
@rfcbot fcp close We don't have any targets for i386/i486 (which don't support CPUID) and we're happy to let SGX targets figure out feature detection on their own. As such, let's just remove |
Team member @Amanieu has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Speaking for myself here: I'd be in favor of having |
The "fully functional" part isn't possible on SGX, where platform support is needed for feature detection. So if the definition is moved to |
I assume it would only exist in core for targets where that is possible, i.e., not the SGX targets. |
It seems pretty strange to me to have target-specific (beyond arch) items in core. |
I mean, it seems pretty strange to me to have architectures which can't actually execute their ISA. |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
This issue tracks the stabilization of the
has_cpuid
intrinsic.The "mini-RFC" is part of the stabilization PR: rust-lang/stdarch#730
cc @rust-lang/libs @alexcrichton
The text was updated successfully, but these errors were encountered: