Expand description
A library to parse the x86 CPUID instruction, written in rust with no external dependencies. The implementation closely resembles the Intel CPUID manual description. The library works with no_std.
§Example
use raw_cpuid::CpuId;
let cpuid = CpuId::new();
if let Some(vf) = cpuid.get_vendor_info() {
assert!(vf.as_str() == "GenuineIntel" || vf.as_str() == "AuthenticAMD");
}
let has_sse = cpuid.get_feature_info().map_or(false, |finfo| finfo.has_sse());
if has_sse {
println!("CPU supports SSE!");
}
if let Some(cparams) = cpuid.get_cache_parameters() {
for cache in cparams {
let size = cache.associativity() * cache.physical_line_partitions() * cache.coherency_line_size() * cache.sets();
println!("L{}-Cache size is {}", cache.level(), size);
}
} else {
println!("No cache parameter information available")
}
§Platform support
CPU vendors may choose to not support certain functions/leafs in cpuid or only support them partially. We highlight this with the following emojis throughout the documentation:
- ✅: This struct/function is fully supported by the vendor.
- 🟡: This struct is partially supported by the vendor, refer to individual functions for more information.
- ❌: This struct/function is not supported by the vendor. When queried on this platform, we will return None/false/0 (or some other sane default).
- ❓: This struct/function is not supported by the vendor according to the manual, but the in practice it still may return valid information.
Note that the presence of a ✅ does not guarantee that a specific feature will exist for your CPU – just that it is potentially supported by the vendor on some of its chips. You will still have to query it at runtime.
Re-exports§
pub use native_cpuid::CpuIdReaderNative;
Modules§
- native_
cpuid - Uses Rust’s
cpuid
function from thearch
module.
Macros§
- cpuid
- Macro which queries cpuid directly.
Structs§
- ApmInfo
- Processor Power Management and RAS Capabilities (LEAF=0x8000_0007).
- Cache
Info - Describes any kind of cache (TLB, Data and Instruction caches plus prefetchers).
- Cache
Info Iter - Iterates over cache information (LEAF=0x02).
- Cache
Parameter - Information about an individual cache in the hierarchy.
- Cache
Parameters Iter - Iterator over caches (LEAF=0x04).
- CpuId
- The main type used to query information about the CPU we’re running on.
- CpuId
Result - Low-level data-structure to store result of cpuid instruction.
- DatInfo
- Deterministic Address Translation Structure
- DatIter
- Deterministic Address Translation Structure Iterator (LEAF=0x18).
- Direct
Cache Access Info - Direct cache access info (LEAF=0x09).
- EpcSection
- EBX:EAX and EDX:ECX provide information on the Enclave Page Cache (EPC) section
- Extended
Features - Structured Extended Feature Identifiers (LEAF=0x07).
- Extended
Processor Feature Identifiers - Extended Processor and Processor Feature Identifiers (LEAF=0x8000_0001)
- Extended
State - ExtendedState subleaf structure for things that need to be restored.
- Extended
State Info - Information for saving/restoring extended register state (LEAF=0x0D).
- Extended
State Iter - Yields ExtendedState structs.
- Extended
Topology Iter - Information about topology (LEAF=0x0B).
- Extended
Topology Level - Gives information about the current level in the topology.
- Feature
Info - Processor and Processor Feature Identifiers (LEAF=0x01).
- Hypervisor
Info - Information about Hypervisor (LEAF=0x4000_0001)
- L1Cache
TlbInfo - L1 Cache and TLB Information (LEAF=0x8000_0005).
- L2And3
Cache TlbInfo - L2/L3 Cache and TLB Information (LEAF=0x8000_0006).
- L2Cat
Info - L2 Cache Allocation Technology Enumeration Sub-leaf (LEAF=0x10, SUBLEAF=2).
- L3Cat
Info - L3 Cache Allocation Technology Enumeration Sub-leaf (LEAF=0x10, SUBLEAF=1).
- L3Monitoring
Info - Information about L3 cache monitoring.
- MemBw
Allocation Info - Memory Bandwidth Allocation Enumeration Sub-leaf (LEAF=0x10, SUBLEAF=3).
- Memory
Encryption Info - Encrypted Memory Capabilities (LEAF=0x8000_001F).
- Monitor
Mwait Info - Information about how monitor/mwait works on this CPU (LEAF=0x05).
- Performance
Monitoring Info - Info about performance monitoring – how many counters etc. (LEAF=0x0A)
- Performance
Optimization Info - Performance Optimization Identifier (LEAF=0x8000_001A).
- Processor
Brand String - Processor name (LEAF=0x8000_0002..=0x8000_0004).
- Processor
Capacity AndFeature Info - Processor Capacity Parameters and Extended Feature Identification (LEAF=0x8000_0008).
- Processor
Frequency Info - Processor Frequency Information (LEAF=0x16).
- Processor
Serial - Processor Serial Number (LEAF=0x3).
- Processor
Topology Info - Processor Topology Information (LEAF=0x8000_001E).
- Processor
Trace Info - Intel Processor Trace Information (LEAF=0x14).
- RdtAllocation
Info - Quality of service enforcement information (LEAF=0x10).
- RdtMonitoring
Info - Intel Resource Director Technology RDT (LEAF=0x0F).
- SgxInfo
- Intel SGX Capability Enumeration Leaf (LEAF=0x12).
- SgxSection
Iter - Iterator over the SGX sub-leafs (ECX >= 2).
- SoCVendor
Attributes Iter - Iterator for SoC vendor attributes.
- SoCVendor
Brand - A vendor brand string as queried from the cpuid leaf.
- SoCVendor
Info - SoC vendor specific information (LEAF=0x17).
- SvmFeatures
- Information about the SVM features that the processory supports (LEAF=0x8000_000A).
- Thermal
Power Info - Query information about thermal and power management features of the CPU (LEAF=0x06).
- Tlb1gb
Page Info - TLB 1-GiB Pages Information (LEAF=0x8000_0019).
- TscInfo
- Time Stamp Counter/Core Crystal Clock Information (LEAF=0x15).
- Vendor
Info - Vendor Info String (LEAF=0x0)
Enums§
- Associativity
- Info about cache Associativity.
- Cache
Info Type - What type of cache are we dealing with?
- Cache
Type - Info about a what a given cache caches (instructions, data, etc.)
- DatType
- Deterministic Address Translation cache type (EDX bits 04 – 00)
- Extended
Register State Location - Where the extended register state is stored.
- Extended
Register Type - What kidn of extended register state this is.
- Hypervisor
- Identifies the different Hypervisor products.
- SgxSection
Info - Intel SGX EPC Enumeration Leaf
- Topology
Type - What type of core we have at this level in the topology (real CPU or hyper-threaded).
Constants§
- CACHE_
INFO_ TABLE - This table is taken from Intel manual (Section CPUID instruction).
Traits§
- CpuId
Reader - Implements function to read/write cpuid. This allows to conveniently swap out the underlying cpuid implementation with one that returns data that is deterministic (for unit-testing).