use crate::{CpuId, CpuIdResult};
static CPUID_VALUE_MAP: phf::Map<u64, CpuIdResult> = phf::phf_map! {
0x00000000_00000000u64 => CpuIdResult { eax: 0x00000020, ebx: 0x756e6547, ecx: 0x6c65746e, edx: 0x49656e69 },
0x00000001_00000000u64 => CpuIdResult { eax: 0x00090672, ebx: 0x00800800, ecx: 0x7ffafbff, edx: 0xbfebfbff },
0x00000002_00000000u64 => CpuIdResult { eax: 0x00feff01, ebx: 0x000000f0, ecx: 0x00000000, edx: 0x00000000 },
0x00000003_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000004_00000000u64 => CpuIdResult { eax: 0xfc004121, ebx: 0x02c0003f, ecx: 0x0000003f, edx: 0x00000000 },
0x00000004_00000001u64 => CpuIdResult { eax: 0xfc004122, ebx: 0x01c0003f, ecx: 0x0000003f, edx: 0x00000000 },
0x00000004_00000002u64 => CpuIdResult { eax: 0xfc01c143, ebx: 0x0240003f, ecx: 0x000007ff, edx: 0x00000000 },
0x00000004_00000003u64 => CpuIdResult { eax: 0xfc1fc163, ebx: 0x0240003f, ecx: 0x00009fff, edx: 0x00000004 },
0x00000005_00000000u64 => CpuIdResult { eax: 0x00000040, ebx: 0x00000040, ecx: 0x00000003, edx: 0x10102020 },
0x00000006_00000000u64 => CpuIdResult { eax: 0x00dfcff7, ebx: 0x00000002, ecx: 0x00000401, edx: 0x00000003 },
0x00000007_00000000u64 => CpuIdResult { eax: 0x00000002, ebx: 0x239c27eb, ecx: 0x98c027bc, edx: 0xfc1cc410 },
0x00000007_00000001u64 => CpuIdResult { eax: 0x00400810, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000007_00000002u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000001 },
0x00000008_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000009_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000a_00000000u64 => CpuIdResult { eax: 0x07300605, ebx: 0x00000000, ecx: 0x00000007, edx: 0x00008603 },
0x0000000b_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x00000002, ecx: 0x00000100, edx: 0x00000000 },
0x0000000b_00000001u64 => CpuIdResult { eax: 0x00000007, ebx: 0x00000014, ecx: 0x00000201, edx: 0x00000000 },
0x0000000c_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000000u64 => CpuIdResult { eax: 0x00000207, ebx: 0x00000a88, ecx: 0x00000a88, edx: 0x00000000 },
0x0000000d_00000001u64 => CpuIdResult { eax: 0x0000000f, ebx: 0x00000670, ecx: 0x00019900, edx: 0x00000000 },
0x0000000d_00000002u64 => CpuIdResult { eax: 0x00000100, ebx: 0x00000240, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000008u64 => CpuIdResult { eax: 0x00000080, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000d_00000009u64 => CpuIdResult { eax: 0x00000008, ebx: 0x00000a80, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_0000000bu64 => CpuIdResult { eax: 0x00000010, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000d_0000000cu64 => CpuIdResult { eax: 0x00000018, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000d_0000000fu64 => CpuIdResult { eax: 0x00000328, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000d_00000010u64 => CpuIdResult { eax: 0x00000008, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000e_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000f_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000010_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000011_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000012_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000013_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000014_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x0000005f, ecx: 0x00000007, edx: 0x00000000 },
0x00000014_00000001u64 => CpuIdResult { eax: 0x02490002, ebx: 0x003f003f, ecx: 0x00000000, edx: 0x00000000 },
0x00000015_00000000u64 => CpuIdResult { eax: 0x00000002, ebx: 0x000000bc, ecx: 0x0249f000, edx: 0x00000000 },
0x00000016_00000000u64 => CpuIdResult { eax: 0x00000e10, ebx: 0x00001388, ecx: 0x00000064, edx: 0x00000000 },
0x00000017_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000018_00000000u64 => CpuIdResult { eax: 0x00000008, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000018_00000001u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00080001, ecx: 0x00000020, edx: 0x00004022 },
0x00000018_00000002u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00080006, ecx: 0x00000004, edx: 0x00004022 },
0x00000018_00000003u64 => CpuIdResult { eax: 0x00000000, ebx: 0x0010000f, ecx: 0x00000001, edx: 0x00004125 },
0x00000018_00000004u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00040001, ecx: 0x00000010, edx: 0x00004024 },
0x00000018_00000005u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00040006, ecx: 0x00000008, edx: 0x00004024 },
0x00000018_00000006u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00080008, ecx: 0x00000001, edx: 0x00004124 },
0x00000018_00000007u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00080007, ecx: 0x00000080, edx: 0x00004043 },
0x00000018_00000008u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00080009, ecx: 0x00000080, edx: 0x00004043 },
0x00000019_00000000u64 => CpuIdResult { eax: 0x00000007, ebx: 0x00000014, ecx: 0x00000003, edx: 0x00000000 },
0x0000001a_00000000u64 => CpuIdResult { eax: 0x40000001, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000001b_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x00000001, ecx: 0x00000000, edx: 0x00000000 },
0x0000001c_00000000u64 => CpuIdResult { eax: 0x4000000b, ebx: 0x00000007, ecx: 0x00000007, edx: 0x00000000 },
0x0000001d_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000001e_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000001f_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x00000002, ecx: 0x00000100, edx: 0x00000000 },
0x0000001f_00000001u64 => CpuIdResult { eax: 0x00000007, ebx: 0x00000014, ecx: 0x00000201, edx: 0x00000000 },
0x0000001f_00000002u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000002, edx: 0x00000000 },
0x00000020_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000001, ecx: 0x00000000, edx: 0x00000000 },
0x20000000_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000001, ecx: 0x00000000, edx: 0x00000000 },
0x80000000_00000000u64 => CpuIdResult { eax: 0x80000008, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80000001_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000121, edx: 0x2c100800 },
0x80000002_00000000u64 => CpuIdResult { eax: 0x68743231, ebx: 0x6e654720, ecx: 0x746e4920, edx: 0x52286c65 },
0x80000003_00000000u64 => CpuIdResult { eax: 0x6f432029, ebx: 0x54286572, ecx: 0x6920294d, edx: 0x32312d37 },
0x80000004_00000000u64 => CpuIdResult { eax: 0x4b303037, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80000005_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80000006_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x05007040, edx: 0x00000000 },
0x80000007_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000100 },
0x80000008_00000000u64 => CpuIdResult { eax: 0x0000302e, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80860000_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000001, ecx: 0x00000000, edx: 0x00000000 },
0xc0000000_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000001, ecx: 0x00000000, edx: 0x00000000 },
};
fn cpuid_reader(eax: u32, ecx: u32) -> CpuIdResult {
let key = (eax as u64) << u32::BITS | ecx as u64;
CPUID_VALUE_MAP[&key]
}
#[test]
fn vendor_check() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let v = cpuid.get_vendor_info().expect("Need to find vendor info");
assert_eq!(v.as_str(), "GenuineIntel");
}
#[test]
fn version_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let f = cpuid.get_feature_info().expect("Need to find feature info");
assert_eq!(f.base_family_id(), 6);
assert_eq!(f.base_model_id(), 7);
assert_eq!(f.stepping_id(), 2);
assert_eq!(f.extended_family_id(), 0);
assert_eq!(f.extended_model_id(), 9);
assert_eq!(f.family_id(), 6);
assert_eq!(f.model_id(), 151);
assert_eq!(f.max_logical_processor_ids(), 128);
assert_eq!(f.initial_local_apic_id(), 0);
assert_eq!(f.cflush_cache_line_size(), 0x8);
assert_eq!(f.brand_index(), 0x0);
assert!(f.has_fpu());
assert!(f.has_vme());
assert!(f.has_de());
assert!(f.has_pse());
assert!(f.has_tsc());
assert!(f.has_msr());
assert!(f.has_pae());
assert!(f.has_mce());
assert!(f.has_cmpxchg8b());
assert!(f.has_apic());
assert!(f.has_sysenter_sysexit());
assert!(f.has_mtrr());
assert!(f.has_pge());
assert!(f.has_mca());
assert!(f.has_cmov());
assert!(f.has_pat());
assert!(f.has_pse36());
assert!(!f.has_psn());
assert!(f.has_clflush());
assert!(f.has_ds());
assert!(f.has_acpi());
assert!(f.has_mmx());
assert!(f.has_fxsave_fxstor());
assert!(f.has_sse());
assert!(f.has_sse2());
assert!(f.has_ss());
assert!(f.has_htt());
assert!(f.has_tm());
assert!(f.has_pbe());
assert!(f.has_sse3());
assert!(f.has_pclmulqdq());
assert!(f.has_ds_area());
assert!(f.has_monitor_mwait());
assert!(f.has_cpl());
assert!(f.has_vmx());
assert!(f.has_smx());
assert!(f.has_eist());
assert!(f.has_tm2());
assert!(f.has_ssse3());
assert!(!f.has_cnxtid());
assert!(f.has_fma());
assert!(f.has_cmpxchg16b());
assert!(f.has_pdcm());
assert!(f.has_pcid());
assert!(!f.has_dca());
assert!(f.has_sse41());
assert!(f.has_sse42());
assert!(f.has_x2apic());
assert!(f.has_movbe());
assert!(f.has_popcnt());
assert!(f.has_tsc_deadline());
assert!(f.has_aesni());
assert!(f.has_xsave());
assert!(f.has_oxsave());
assert!(f.has_avx());
assert!(f.has_f16c());
assert!(f.has_rdrand());
assert!(!f.has_hypervisor());
}
#[test]
fn cache_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let ci = cpuid.get_cache_info().expect("Leaf is supported");
for (idx, cache) in ci.enumerate() {
match idx {
0 => assert_eq!(cache.num, 0xf0),
1 => assert_eq!(cache.num, 0xff),
2 => assert_eq!(cache.num, 0xfe),
3 => assert_eq!(cache.num, 0x03),
4 => assert_eq!(cache.num, 0xf0),
5 => assert_eq!(cache.num, 0x76),
6 => assert_eq!(cache.num, 0xc3),
_ => unreachable!(),
}
}
}
#[test]
fn processor_serial() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let psn = cpuid.get_processor_serial().expect("Leaf is supported");
assert_eq!(psn.serial_lower(), 0x0);
assert_eq!(psn.serial_middle(), 0x0);
}
#[test]
fn monitor_mwait() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mw = cpuid.get_monitor_mwait_info().expect("Leaf is supported");
assert_eq!(mw.largest_monitor_line(), 64);
assert_eq!(mw.smallest_monitor_line(), 64);
assert!(mw.interrupts_as_break_event());
assert!(mw.extensions_supported());
assert_eq!(mw.supported_c0_states(), 0x0);
assert_eq!(mw.supported_c1_states(), 0x2);
assert_eq!(mw.supported_c2_states(), 0x0);
assert_eq!(mw.supported_c3_states(), 0x2);
assert_eq!(mw.supported_c4_states(), 0x0);
assert_eq!(mw.supported_c5_states(), 0x1);
assert_eq!(mw.supported_c6_states(), 0x0);
assert_eq!(mw.supported_c7_states(), 0x1);
}
#[test]
fn thermal_power() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mw = cpuid.get_thermal_power_info().expect("Leaf is supported");
assert!(mw.has_dts());
assert!(mw.has_turbo_boost());
assert!(mw.has_arat());
assert!(mw.has_pln());
assert!(mw.has_ecmd());
assert!(mw.has_ptm());
assert!(mw.has_hwp());
assert!(mw.has_hwp_notification());
assert!(mw.has_hwp_activity_window());
assert!(mw.has_hwp_energy_performance_preference());
assert!(mw.has_hwp_package_level_request());
assert!(!mw.has_hdc());
assert!(mw.has_turbo_boost3());
assert!(mw.has_hwp_capabilities());
assert!(mw.has_hwp_peci_override());
assert!(mw.has_flexible_hwp());
assert!(mw.has_hwp_fast_access_mode());
assert!(mw.has_hw_coord_feedback());
assert!(mw.has_ignore_idle_processor_hwp_request());
assert_eq!(mw.dts_irq_threshold(), 0x2);
assert!(!mw.has_energy_bias_pref());
}
#[test]
fn extended_features() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_extended_feature_info()
.expect("Leaf is supported");
assert!(e.has_fsgsbase());
assert!(e.has_tsc_adjust_msr());
assert!(!e.has_sgx());
assert!(e.has_bmi1());
assert!(!e.has_hle());
assert!(e.has_avx2());
assert!(e.has_fdp());
assert!(e.has_smep());
assert!(e.has_bmi2());
assert!(e.has_rep_movsb_stosb());
assert!(e.has_invpcid());
assert!(!e.has_rtm());
assert!(!e.has_rdtm());
assert!(e.has_fpu_cs_ds_deprecated());
assert!(!e.has_mpx());
assert!(!e.has_rdta());
assert!(!e.has_avx512f());
assert!(!e.has_avx512dq());
assert!(e.has_rdseed());
assert!(e.has_adx());
assert!(e.has_smap());
assert!(!e.has_avx512_ifma());
assert!(e.has_clflushopt());
assert!(e.has_clwb());
assert!(e.has_processor_trace());
assert!(!e.has_avx512pf());
assert!(!e.has_avx512er());
assert!(!e.has_avx512cd());
assert!(e.has_sha());
assert!(!e.has_avx512bw());
assert!(!e.has_avx512vl());
assert!(!e.has_prefetchwt1());
assert!(e.has_umip());
assert!(e.has_pku());
assert!(e.has_ospke());
assert!(!e.has_avx512vnni());
assert!(e.has_rdpid());
assert!(e.has_waitpkg());
assert!(!e.has_sgx_lc());
assert_eq!(e.mawau_value(), 0x0);
}
#[test]
fn direct_cache_access() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let dca = cpuid.get_direct_cache_access_info().expect("Leaf exists");
assert_eq!(dca.get_dca_cap_value(), 0x0);
}
#[test]
fn perfmon_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let pm = cpuid
.get_performance_monitoring_info()
.expect("Leaf exists");
assert_eq!(pm.version_id(), 0x5);
assert_eq!(pm.number_of_counters(), 0x6);
assert_eq!(pm.counter_bit_width(), 0x30);
assert_eq!(pm.ebx_length(), 0x7);
assert!(!pm.is_core_cyc_ev_unavailable());
assert!(!pm.is_inst_ret_ev_unavailable());
assert!(!pm.is_ref_cycle_ev_unavailable());
assert!(!pm.is_cache_ref_ev_unavailable());
assert!(!pm.is_ll_cache_miss_ev_unavailable());
assert!(!pm.is_branch_inst_ret_ev_unavailable());
assert!(!pm.is_branch_midpred_ev_unavailable());
assert_eq!(pm.fixed_function_counters(), 0x3);
assert_eq!(pm.fixed_function_counters_bit_width(), 0x30);
assert!(pm.has_any_thread_deprecation());
}
#[test]
fn extended_topology_info() {
use crate::TopologyType;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mut e = cpuid
.get_extended_topology_info()
.expect("Leaf is supported");
let t = e.next().expect("Have level 0");
assert_eq!(t.x2apic_id(), 0);
assert_eq!(t.level_number(), 0);
assert_eq!(t.level_type(), TopologyType::SMT);
assert_eq!(t.shift_right_for_next_apic_id(), 0x1);
assert_eq!(t.processors(), 2);
let t = e.next().expect("Have level 1");
assert_eq!(t.level_number(), 1);
assert_eq!(t.level_type(), TopologyType::Core);
assert_eq!(t.shift_right_for_next_apic_id(), 0x7);
assert_eq!(t.processors(), 20);
assert_eq!(t.x2apic_id(), 0);
}
#[test]
fn extended_topology_info_v2() {
use crate::TopologyType;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mut e = cpuid
.get_extended_topology_info_v2()
.expect("Leaf is supported");
let t = e.next().expect("Have level 0");
assert_eq!(t.x2apic_id(), 0);
assert_eq!(t.level_number(), 0);
assert_eq!(t.level_type(), TopologyType::SMT);
assert_eq!(t.shift_right_for_next_apic_id(), 0x1);
assert_eq!(t.processors(), 2);
let t = e.next().expect("Have level 1");
assert_eq!(t.level_number(), 1);
assert_eq!(t.level_type(), TopologyType::Core);
assert_eq!(t.shift_right_for_next_apic_id(), 0x7);
assert_eq!(t.processors(), 20);
assert_eq!(t.x2apic_id(), 0);
}
#[test]
fn extended_state_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_extended_state_info().expect("Leaf is supported");
assert!(e.xcr0_supports_legacy_x87());
assert!(e.xcr0_supports_sse_128());
assert!(e.xcr0_supports_avx_256());
assert!(!e.xcr0_supports_mpx_bndregs());
assert!(!e.xcr0_supports_mpx_bndcsr());
assert!(!e.xcr0_supports_avx512_opmask());
assert!(!e.xcr0_supports_avx512_zmm_hi256());
assert!(!e.xcr0_supports_avx512_zmm_hi16());
assert!(e.ia32_xss_supports_pt());
assert!(e.xcr0_supports_pkru());
assert!(!e.ia32_xss_supports_hdc());
assert_eq!(e.xsave_area_size_enabled_features(), 2696);
assert_eq!(e.xsave_area_size_supported_features(), 2696);
assert!(e.has_xsaveopt());
assert!(e.has_xsavec());
assert!(e.has_xgetbv());
assert!(e.has_xsaves_xrstors());
assert_eq!(e.xsave_size(), 1648);
let mut e = e.iter();
let ee = e.next().expect("Has level 2");
assert_eq!(ee.size(), 256);
assert_eq!(ee.offset(), 576);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 3");
assert_eq!(ee.size(), 128);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 4");
assert_eq!(ee.size(), 8);
assert_eq!(ee.offset(), 2688);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 5");
assert_eq!(ee.size(), 16);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 6");
assert_eq!(ee.size(), 24);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 7");
assert_eq!(ee.size(), 808);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 8");
assert_eq!(ee.size(), 8);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
}
#[test]
fn rdt_monitoring_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_rdt_monitoring_info().expect("Leaf is supported");
assert_eq!(e.rmid_range(), 0);
assert!(!e.has_l3_monitoring());
}
#[test]
fn rdt_allocation_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_rdt_allocation_info().expect("Leaf is supported");
assert!(!e.has_l3_cat());
assert!(!e.has_l2_cat());
assert!(!e.has_memory_bandwidth_allocation());
assert!(e.l2_cat().is_none());
assert!(e.l3_cat().is_none());
}
#[test]
fn sgx_test() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
assert!(cpuid.get_sgx_info().is_none());
}
#[test]
fn processor_trace() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let pt = cpuid.get_processor_trace_info().expect("Leaf is available");
assert!(pt.has_rtit_cr3_match());
assert!(pt.has_configurable_psb_and_cycle_accurate_mode());
assert!(pt.has_ip_tracestop_filtering());
assert!(pt.has_mtc_timing_packet_coefi_suppression());
assert!(pt.has_ptwrite());
assert!(!pt.has_power_event_trace());
assert!(pt.has_topa());
assert!(pt.has_topa_maximum_entries());
assert!(pt.has_single_range_output_scheme());
assert!(!pt.has_trace_transport_subsystem());
assert!(!pt.has_lip_with_cs_base());
assert_eq!(pt.configurable_address_ranges(), 2);
assert_eq!(pt.supported_mtc_period_encodings(), 585);
assert_eq!(pt.supported_cycle_threshold_value_encodings(), 63);
assert_eq!(pt.supported_psb_frequency_encodings(), 63);
}
#[test]
fn tsc() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_tsc_info().expect("Leaf is available");
assert_eq!(e.denominator(), 2);
assert_eq!(e.numerator(), 188);
assert_eq!(e.nominal_frequency(), 38400000);
assert_eq!(e.tsc_frequency(), Some(3609600000));
}
#[test]
fn processor_frequency() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_frequency_info()
.expect("Leaf is supported");
assert_eq!(e.processor_base_frequency(), 3600);
assert_eq!(e.processor_max_frequency(), 5000);
assert_eq!(e.bus_frequency(), 100);
}
#[test]
fn extended_processor_and_feature_identifiers() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_extended_processor_and_feature_identifiers()
.expect("Leaf is supported");
assert_eq!(e.pkg_type(), 0x0); assert_eq!(e.brand_id(), 0x0);
assert!(e.has_lahf_sahf());
assert!(!e.has_cmp_legacy());
assert!(!e.has_svm());
assert!(!e.has_ext_apic_space());
assert!(!e.has_alt_mov_cr8());
assert!(e.has_lzcnt());
assert!(!e.has_sse4a());
assert!(!e.has_misaligned_sse_mode());
assert!(e.has_prefetchw());
assert!(!e.has_osvw());
assert!(!e.has_ibs());
assert!(!e.has_xop());
assert!(!e.has_skinit());
assert!(!e.has_wdt());
assert!(!e.has_lwp());
assert!(!e.has_fma4());
assert!(!e.has_tbm());
assert!(!e.has_topology_extensions());
assert!(!e.has_perf_cntr_extensions());
assert!(!e.has_nb_perf_cntr_extensions());
assert!(!e.has_data_access_bkpt_extension());
assert!(!e.has_perf_tsc());
assert!(!e.has_perf_cntr_llc_extensions());
assert!(!e.has_monitorx_mwaitx());
assert!(!e.has_addr_mask_extension());
assert!(e.has_syscall_sysret());
assert!(e.has_execute_disable());
assert!(!e.has_mmx_extensions());
assert!(!e.has_fast_fxsave_fxstor());
assert!(e.has_1gib_pages());
assert!(e.has_rdtscp());
assert!(e.has_64bit_mode());
assert!(!e.has_amd_3dnow_extensions());
assert!(!e.has_3dnow());
}
#[test]
fn brand_string() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_brand_string()
.expect("Leaf is supported");
assert_eq!(e.as_str(), "12th Gen Intel(R) Core(TM) i7-12700K");
}
#[test]
fn l1_tlb_cache() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
assert!(cpuid.get_l1_cache_and_tlb_info().is_none());
}
#[test]
fn l2_l3_tlb_cache() {
use crate::Associativity;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_l2_l3_cache_and_tlb_info()
.expect("Leaf is supported");
assert_eq!(e.itlb_2m_4m_associativity(), Associativity::Disabled);
assert_eq!(e.itlb_2m_4m_size(), 0);
assert_eq!(e.dtlb_2m_4m_associativity(), Associativity::Disabled);
assert_eq!(e.dtlb_2m_4m_size(), 0);
assert_eq!(e.itlb_4k_size(), 0);
assert_eq!(e.itlb_4k_associativity(), Associativity::Disabled);
assert_eq!(e.dtlb_4k_size(), 0);
assert_eq!(e.dtlb_4k_associativity(), Associativity::Disabled);
assert_eq!(e.l2cache_line_size(), 64);
assert_eq!(e.l2cache_lines_per_tag(), 0);
assert_eq!(e.l2cache_associativity(), Associativity::Unknown);
assert_eq!(e.l2cache_size(), 1280);
assert_eq!(e.l3cache_line_size(), 0);
assert_eq!(e.l3cache_lines_per_tag(), 0);
assert_eq!(e.l3cache_associativity(), Associativity::Disabled);
assert_eq!(e.l3cache_size(), 0);
}
#[test]
fn apm() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_advanced_power_mgmt_info()
.expect("Leaf is supported");
assert!(!e.has_mca_overflow_recovery());
assert!(!e.has_succor());
assert!(!e.has_hwa());
assert_eq!(e.cpu_pwr_sample_time_ratio(), 0x0);
assert!(!e.has_ts());
assert!(!e.has_freq_id_ctrl());
assert!(!e.has_volt_id_ctrl());
assert!(!e.has_thermtrip());
assert!(!e.has_tm());
assert!(!e.has_100mhz_steps());
assert!(!e.has_hw_pstate());
assert!(e.has_invariant_tsc()); assert!(!e.has_cpb());
assert!(!e.has_ro_effective_freq_iface());
assert!(!e.has_feedback_iface());
assert!(!e.has_power_reporting_iface());
}
#[test]
fn processor_capcity_features() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_capacity_feature_info()
.expect("Leaf is supported");
assert_eq!(e.physical_address_bits(), 46);
assert_eq!(e.linear_address_bits(), 48);
assert_eq!(e.guest_physical_address_bits(), 0);
assert!(!e.has_cl_zero());
assert!(!e.has_inst_ret_cntr_msr());
assert!(!e.has_restore_fp_error_ptrs());
assert!(!e.has_invlpgb());
assert!(!e.has_rdpru());
assert!(!e.has_mcommit());
assert!(!e.has_wbnoinvd());
assert!(!e.has_int_wbinvd());
assert!(!e.has_unsupported_efer_lmsle());
assert!(!e.has_invlpgb_nested());
assert_eq!(e.invlpgb_max_pages(), 0x0);
assert_eq!(e.maximum_logical_processors(), 1); assert_eq!(e.num_phys_threads(), 1); assert_eq!(e.apic_id_size(), 0);
assert_eq!(e.perf_tsc_size(), 40); assert_eq!(e.max_rdpru_id(), 0);
}
#[test]
fn get_deterministic_address_translation_info() {
use crate::DatType;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mut e = cpuid
.get_deterministic_address_translation_info()
.expect("Leaf is supported");
let t = e.next().expect("Have level 1");
assert!(t.has_4k_entries());
assert!(!t.has_2mb_entries());
assert!(!t.has_4mb_entries());
assert!(!t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 8);
assert_eq!(t.sets(), 32);
assert_eq!(t.cache_type(), DatType::InstructionTLB);
assert_eq!(t.cache_level(), 1);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 2");
assert!(!t.has_4k_entries());
assert!(t.has_2mb_entries());
assert!(t.has_4mb_entries());
assert!(!t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 8);
assert_eq!(t.sets(), 4);
assert_eq!(t.cache_type(), DatType::InstructionTLB);
assert_eq!(t.cache_level(), 1);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 3");
assert!(t.has_4k_entries());
assert!(t.has_2mb_entries());
assert!(t.has_4mb_entries());
assert!(t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 16);
assert_eq!(t.sets(), 1);
assert_eq!(t.cache_type(), DatType::StoreOnly);
assert_eq!(t.cache_level(), 1);
assert!(t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 4");
assert!(t.has_4k_entries());
assert!(!t.has_2mb_entries());
assert!(!t.has_4mb_entries());
assert!(!t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 4);
assert_eq!(t.sets(), 16);
assert_eq!(t.cache_type(), DatType::LoadOnly);
assert_eq!(t.cache_level(), 1);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 5");
assert!(!t.has_4k_entries());
assert!(t.has_2mb_entries());
assert!(t.has_4mb_entries());
assert!(!t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 4);
assert_eq!(t.sets(), 8);
assert_eq!(t.cache_type(), DatType::LoadOnly);
assert_eq!(t.cache_level(), 1);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 6");
assert!(!t.has_4k_entries());
assert!(!t.has_2mb_entries());
assert!(!t.has_4mb_entries());
assert!(t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 8);
assert_eq!(t.sets(), 1);
assert_eq!(t.cache_type(), DatType::LoadOnly);
assert_eq!(t.cache_level(), 1);
assert!(t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 7");
assert!(t.has_4k_entries());
assert!(t.has_2mb_entries());
assert!(t.has_4mb_entries());
assert!(!t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 8);
assert_eq!(t.sets(), 128);
assert_eq!(t.cache_type(), DatType::UnifiedTLB);
assert_eq!(t.cache_level(), 2);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
let t = e.next().expect("Have level 8");
assert!(t.has_4k_entries());
assert!(!t.has_2mb_entries());
assert!(!t.has_4mb_entries());
assert!(t.has_1gb_entries());
assert_eq!(t.partitioning(), 0);
assert_eq!(t.ways(), 8);
assert_eq!(t.sets(), 128);
assert_eq!(t.cache_type(), DatType::UnifiedTLB);
assert_eq!(t.cache_level(), 2);
assert!(!t.is_fully_associative());
assert_eq!(t.max_addressable_ids(), 2);
}
#[test]
fn get_soc_vendor() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_soc_vendor_info().expect("Leaf is supported");
assert_eq!(e.get_project_id(), 0);
assert_eq!(e.get_soc_vendor_id(), 0);
assert_eq!(e.get_stepping_id(), 0);
if let Some(attr_iter) = e.get_vendor_attributes() {
for attr in attr_iter {
println!("{:?}", attr);
}
}
println!("{:?}", e.get_vendor_brand());
}