#x86 #cpuid #libcore #parser #no-alloc #os

no-std bin+lib raw-cpuid

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 does only depend on libcore.

40 stable releases (11 major)

11.2.0 Oct 2, 2024
11.1.0 Jul 16, 2024
11.0.2 Apr 29, 2024
11.0.1 May 3, 2023
0.0.2 Mar 24, 2015

#3 in Hardware support

Download history 472053/week @ 2024-08-02 552337/week @ 2024-08-09 577357/week @ 2024-08-16 564765/week @ 2024-08-23 522063/week @ 2024-08-30 606270/week @ 2024-09-06 558674/week @ 2024-09-13 670353/week @ 2024-09-20 655406/week @ 2024-09-27 757475/week @ 2024-10-04 697808/week @ 2024-10-11 758968/week @ 2024-10-18 798673/week @ 2024-10-25 715093/week @ 2024-11-01 746227/week @ 2024-11-08 604368/week @ 2024-11-15

3,009,720 downloads per month
Used in 1,443 crates (65 directly)

MIT license

515KB
9K SLoC

cpuid Crates.io Standard checks

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 in no_std environments. Some additional cargo features require std (e.g., pretty printing, serialization).

  • For Intel platforms: The code should be in sync with the March 2018 revision of the Intel Architectures SDM.
  • For AMD platforms it should be in sync with the AMD64 systems manual no. 24594, Revision 3.32 (March 2021).

Library usage

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")
}

cpuid binary

raw-cpuid ships with a cpuid binary that can be installed to inspect the output of the CPUID instruction on a host system.

To install, use:

cargo install raw-cpuid --features cli

The cli feature is currently required to build the binary version due to cargo limitations.

Documentation

Dependencies

~0–8.5MB
~73K SLoC