Skip to main content

CpuidPolicy

Struct CpuidPolicy 

Source
pub struct CpuidPolicy {
Show 15 fields pub max_basic_leaf: u32, pub max_extended_leaf: u32, pub family: u32, pub model: u32, pub stepping: u32, pub cores: u32, pub threads: u32, pub leaf1_ecx: u32, pub leaf1_edx: u32, pub extended1_ecx: u32, pub extended1_edx: u32, pub tsc_ratio_denominator: u32, pub tsc_ratio_numerator: u32, pub crystal_hz: u32, pub base_mhz: u32,
}
Expand description

Guest-visible CPU description.

The policy is a small Copy value: the exit loop keeps one per world in its crate::s9vm::machine::Machine and replays every CPUID exit against it. CpuidPolicy::default is a safe, boot-capable 64-bit profile: family 6, one core, one thread, no nested virtualization, no XSAVE.

The fields are public so the syscall layer can assemble a policy from the ABI structure; the accessors and feature helpers enforce the invariants documented at module level.

Fields§

§max_basic_leaf: u32

Highest basic leaf, reported by CPUID.0:EAX.

§max_extended_leaf: u32

Highest extended leaf, reported by CPUID.0x8000_0000:EAX.

§family: u32

Guest-visible family (CPUID.1:EAX[11:8]).

§model: u32

Guest-visible model, extended-model bits included.

§stepping: u32

Guest-visible stepping.

§cores: u32

Number of physical cores per package (at least one).

§threads: u32

Number of hardware threads per core (at least one).

§leaf1_ecx: u32

Raw CPUID.1:ECX mask; forbidden bits are filtered when read.

§leaf1_edx: u32

Raw CPUID.1:EDX mask.

§extended1_ecx: u32

Raw CPUID.0x8000_0001:ECX mask; forbidden bits are filtered when read.

§extended1_edx: u32

Raw CPUID.0x8000_0001:EDX mask.

§tsc_ratio_denominator: u32

CPUID.0x15:EAX : TSC/core-crystal ratio denominator.

Zero publishes the host value from the crate::s9vm::tsc cache, or nothing when the host frequency is unknown.

§tsc_ratio_numerator: u32

CPUID.0x15:EBX : TSC/core-crystal ratio numerator.

§crystal_hz: u32

CPUID.0x15:ECX : core-crystal frequency, in hertz.

§base_mhz: u32

CPUID.0x16:EAX : nominal base frequency, in megahertz.

Implementations§

Source§

impl CpuidPolicy

Source

pub const fn new() -> Self

Builds the safe default profile.

This is a const fn so a policy can back a static without runtime initialization.

Source

pub fn set_tsc_frequency(&mut self, frequency: TscFrequency)

Publishes frequency in CPUID leaves 0x15 and 0x16.

The four fields are filled from TscFrequency::cpuid_leaves. A caller that leaves them at zero keeps the host-derived fallback, which is the right default for a world that should see the real host TSC.

Source

pub fn logical_processors(&self) -> u32

Number of logical processors per package, clamped to the 8-bit CPUID.1:EBX[23:16] field. Never zero: an empty policy still describes one processor.

Source

pub fn effective_leaf1_ecx(&self) -> u32

Effective CPUID.1:ECX, with the forbidden bits cleared.

Source

pub fn effective_extended1_ecx(&self) -> u32

Effective CPUID.0x8000_0001:ECX, with the forbidden bits cleared.

Source

pub fn signature(&self) -> u32

CPUID.1:EAX: stepping, model and family encoding.

The extended model field is used when model > 0x0F; the extended family field is only used for families at or above 0x0F, which the default never is. Bits outside the architectural fields are zero.

Source

pub fn set_feature(&mut self, feature: Feature)

Sets one feature bit.

Forbidden bits (LEAF1_ECX_FORBIDDEN, EXTENDED1_ECX_FORBIDDEN) are silently ignored: a caller can never enable nested virtualization through this helper.

Source

pub fn clear_feature(&mut self, feature: Feature)

Clears one feature bit.

Source

pub fn has_feature(&self, feature: Feature) -> bool

Reports whether one feature bit is in effect, forbidden bits included.

Source

pub fn leaf(&self, leaf: u32, subleaf: u32) -> [u32; 4]

Replays one CPUID instruction: returns [EAX, EBX, ECX, EDX].

The function is total and deterministic. leaf == 0 always answers with the advertised basic range; a basic leaf above CpuidPolicy::max_basic_leaf and an extended leaf above CpuidPolicy::max_extended_leaf return zeros, as does every leaf this model does not implement (notably the 0x4000_0000 hypervisor range, because the hypervisor-present bit is never set).

Source

fn vendor_leaf(&self) -> [u32; 4]

CPUID.0: max basic leaf and vendor string.

Source

fn feature_leaf(&self) -> [u32; 4]

CPUID.1: signature, topology count and feature masks.

Source

fn extended_features_leaf(&self) -> [u32; 4]

CPUID.0x8000_0001: extended feature masks.

Source

fn tsc_ratio_leaf(&self) -> [u32; 4]

CPUID.0x15: TSC/core-crystal ratio and crystal frequency.

The policy fields win when they form a usable ratio (non-zero denominator, numerator and crystal). Otherwise the host frequency cache is consulted, so a guest sees the real host TSC frequency even when the policy was not explicitly tuned; when neither source is available the leaf reads as zero and the guest falls back to leaf 0x16 or to calibration.

Source

fn base_frequency_leaf(&self) -> [u32; 4]

CPUID.0x16: nominal base frequency in EAX (megahertz).

The policy field wins; otherwise the host frequency cache is truncated to megahertz. Zero means “not published”.

Source

fn extended_frequency_leaf(&self) -> [u32; 4]

CPUID.0x8000_0007: invariant TSC bit in EDX.

Only bit 8 is set: the guest TSC is the host TSC, s9vm never offsets or scales it, so the invariant-TSC guarantee is published unconditionally. Advanced power-management bits are not advertised.

Source

fn brand_leaf(&self, leaf: u32) -> [u32; 4]

CPUID.0x8000_0002..=0x8000_0004: one quarter of the brand string.

Source

fn address_sizes_leaf(&self) -> [u32; 4]

CPUID.0x8000_0008: physical and virtual address sizes.

Source

fn topology_leaf(&self, subleaf: u32) -> [u32; 4]

Topology enumeration, shared by CPUID.0x0B and CPUID.0x1F.

Both leaves use the same ECX[15:8] level-type encoding (1 = SMT, 2 = core) and terminate with an invalid type. 0x1F additionally carries the x2APIC identifier in EDX[31:16]; with a single package identifier 0 both variants return the same words.

Trait Implementations§

Source§

impl Clone for CpuidPolicy

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CpuidPolicy

Source§

impl Debug for CpuidPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CpuidPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CpuidPolicy

Source§

impl PartialEq for CpuidPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CpuidPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.