Expand description
CPU feature detection via CPUID instruction.
Provides a CpuInfo struct populated at boot time with vendor, model,
feature flags, and XSAVE geometry. All subsequent queries go through
host() which returns the cached result.
Re-exportsΒ§
use crate::sync::SpinLock;πuse alloc::string::String;πuse bitflags::bitflags;πuse core::sync::atomic::AtomicBool;πuse core::sync::atomic::AtomicU64;πuse core::sync::atomic::Ordering;π
StructsΒ§
- CpuFeatures
- Logical internal bitmap.
- CpuInfo
- Cached CPU identification and feature information.
- Xsave
Profile - Cached extended-state save profile, frozen once at
init().
EnumsΒ§
ConstantsΒ§
- XCR0_
AVX - XCR0_
HI16_ ZMM - XCR0_
OPMASK - XCR0_
SSE - XCR0_
X87 - XCR0 component bits.
- XCR0_
ZMM_ HI256
StaticsΒ§
- HOST_
CPU π - HOST_
DEFAULT_ πXCR0_ CACHE - Lock-free cache of the hostβs default XCR0 mask, written once during
init(). Used bynormalized_xcr0()in the context-switch hot path to avoid acquiring theHOST_CPUspinlock with interrupts disabled. - INITIALIZED π
- PROFILE_
AREA_ πSIZE - PROFILE_
XCR0 π - USES_
XSAVE π - Lock-free copy of
CpuInfo::features.contains(XSAVE), published byinit()beforeINITIALIZEDbecomes true and never cleared.
FunctionsΒ§
- boot_
xsave_ profile - Return the frozen XSAVE profile. Before
init()(or without XSAVE), returns the conservative FXSAVE baseline (mask=x87|SSE, 512 bytes). - default_
xcr0_ πfor - Pure helper: the XCR0 mask this kernel would enable for
info(x87 + SSE always, plus AVX / AVX-512 states when the CPU announces them AND the hardware supports the required XCR0 bits). Shared byinit()(pre-lock computation) andhost(). - detect π
- Detect CPU features by interrogating CPUID leaves.
- features_
to_ flags_ string - Build a Linux-style
flagsstring from CPU features. - host
- Return a clone of the cached host CPU info. Panics if
init()not called. - host_
default_ xcr0 - Return the hostβs default XCR0 mask (all supported features).
Safe to call before
init(): returnsXCR0_X87 | XCR0_SSEif not yet initialized. - host_
default_ xcr0_ fast - Return the hostβs default XCR0 mask from the lock-free cache, falling back
to the locked query before
init()is complete. - host_
uses_ xsave - Whether the boot CPU supports XSAVE.
- init
- Detect and cache CPU information. Must be called once at BSP boot.
- tsc_
frequency_ khz - Read the TSC frequency from CPUID leaf 0x15 (Time Stamp Counter and Core
Crystal Clock Information). Returns kHz, or
Noneif the leaf is absent or the core-crystal ratio is not enumerated. - xcr0_
for_ features - Compute the XCR0 mask for a given set of allowed features, clamped to what the host actually supports.
- xsave_
area_ πsize - Walk CPUID leaf 0x0D for the components in
xcr0(skipping supervisor states managed via IA32_XSS) and return the save-area size, clamped tomax_bytesand floored at 576 (legacy area + XSAVE header). - xsave_
size_ πfor_ info - Compute the XSAVE area size needed for a given XCR0 mask directly from a
CpuInfo, without consulting the global cache (host_uses_xsave/host). This is whatinit()must use, because the cache is not yet published wheninit()runs : otherwise AVX/AVX-512 would be given a 512-byte area. - xsave_
size_ for_ xcr0 - Compute the XSAVE area size needed for a given XCR0 mask. Falls back to 512 (FXSAVE) if XSAVE is not supported.