-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Proposal
Rationale
There's a breadth of information available through the CPUID instruction.
Most of this information is not available today from C#, with the exception of information like
support for specific families of HW Intrinsics which is surfaced through the IsSupported JIT time constant/property in each respective group of intrinsics.
I've lightly touched on this in a different issue, but I think this deserves an issue of its own in light with the specific needs that I have in mind.
To name a few types of information that are not currently provided:
- Specific CPU Model (Kaby Lake / Skylake etc.)
- Manufacturer
- Various key HW info like:
- Layout of the caches:
- cache line sizes
- levels
- associativity
- TLB levels, sizes
- Topology of the system (NUMA Nodes, physical/logical mapping) and it's mapping to CPU affinity masks
- Layout of the caches:
This information could be used to select proper code paths or pre-allocate data structures with sizes that relate to the actual HW at hand.
Proposed API
namespace System.Runtime.Intrinsics.X86
{
public class X86Base
{
public static bool IsSupported { get; }
public static (int Eax, int Ebx, int Ecx, int Edx) CpuId(int functionId, int subFunctionId = 0);
}
}Alternatives and Other Considerations
Given that Value Tuples are currently considered AVOID, an alternative is to match the C++ signature of public static void CpuId(int* cpuInfo, int functionId) and public static void CpuId(int* cpuInfo, int functionid, int subFunctionId)
CPUID is not technically a baseline instruction. It requires its own check using the ID bit of the EFLAGS register. However, only CPUs prior to the 486SL (released in 1992) won't have this feature available. In order to minimize the number of ISAs that only contain 1-2 methods (like Lzcnt), it is proposed to simply consider this part of X86Base rather than it be in its own CpuId class.
It is also important to make note that other, cross-platform/architecture methods of obtaining such information are available today, namely the hwloc native library that can provide most if not all of this and beyond through a normalized native API, and ultimately give us this view of our own systems (screenshot of lstopo generated output, part of the hwloc library):

For reference, here's a sample of cpuid generated to show what's up for discussion.
Relevant issues:
https://github.com/dotnet/corefx/issues/22790
https://github.com/dotnet/coreclr/issues/14388