Skip to main content

LocalApic

Struct LocalApic 

Source
pub struct LocalApic {
Show 19 fields id: u32, tpr: u8, svr: u32, esr: u32, isr: [u32; 8], irr: [u32; 8], lvt: [u32; 6], icr_low: u32, icr_high: u32, initial_count: u32, current_count: u32, divide_config: u32, timer_armed: bool, timer_fraction: u64, apic_bus_hz: u64, tsc_fraction: u64, tsc: u64, tsc_deadline: u64, tsc_deadline_armed: bool,
}
Expand description

Complete state of a guest local APIC.

Fields§

§id: u32

APIC identifier (ID register, 8 significant bits in field 31:24).

§tpr: u8

Task priority (TPR), bits 7:0 significant.

§svr: u32

Spurious register (SVR).

§esr: u32

Error status register.

§isr: [u32; 8]

In-Service registers (8 x 32 bits = 256 vectors).

§irr: [u32; 8]

In-Request registers (8 x 32 bits = 256 vectors).

§lvt: [u32; 6]

LVT: timer, thermal, perf, LINT0, LINT1, error.

§icr_low: u32

ICR low/high.

§icr_high: u32§initial_count: u32

Initial and current timer count.

§current_count: u32§divide_config: u32

Timer divider.

§timer_armed: bool

True while a one-shot/periodic count is running.

§timer_fraction: u64

Sub-tick remainder of the divide scaling, in APIC timer input units.

§apic_bus_hz: u64

Nominal APIC timer bus frequency used by LocalApic::advance_tsc.

§tsc_fraction: u64

Remainder of the TSC-to-bus-tick conversion, in TSC cycles.

§tsc: u64

Monotonic model TSC, advanced by LocalApic::advance.

§tsc_deadline: u64

Absolute TSC-deadline value written to IA32_TSC_DEADLINE.

§tsc_deadline_armed: bool

True while the TSC-deadline timer is armed.

Implementations§

Source§

impl LocalApic

Source

pub const fn new(apic_id: u32) -> Self

Creates a local APIC for apic_id, LVTs masked, SVR enabled.

Source

pub const fn apic_id(&self) -> u32

APIC identifier (8-bit value, not shifted).

Source

pub const fn tpr(&self) -> u8

Current task priority.

Source

pub fn ppr(&self) -> u8

Processor priority (TPR and ISR combined), on 8 bits.

Source

pub const fn enabled(&self) -> bool

True if the spurious register enables interrupts.

Source

pub fn has_pending(&self) -> bool

True if at least one vector is pending.

Source

pub fn inject(&mut self, vector: u8)

Injects a vector into the IRR (idempotent).

Source

pub fn pending_vector(&self) -> Option<u8>

Highest-priority deliverable vector, without modifying the state.

Source

pub fn service(&mut self) -> Option<u8>

Moves the deliverable vector from the IRR to the ISR and returns it.

Source

pub fn eoi(&mut self)

Records an EOI: removes the highest-priority vector from the ISR.

Source

pub fn in_service(&self) -> bool

True if a vector is in service.

Source

pub const fn timer_vector(&self) -> u8

Vector programmed in the LVT timer entry.

Source

pub const fn timer_masked(&self) -> bool

True if the LVT timer entry is masked.

Source

pub const fn timer_mode(&self) -> TimerMode

Operating mode of the timer, decoded from the LVT entry.

Source

pub const fn timer_divide(&self) -> u32

Current divide value decoded from the divide configuration register.

Source

pub const fn timer_armed(&self) -> bool

True while either count-based or TSC-deadline timer is running.

Source

pub const fn current_count(&self) -> u32

Current timer count (0 once a one-shot timer has expired).

Source

pub const fn initial_count(&self) -> u32

Last value written to the initial-count register.

Source

pub const fn tsc_deadline(&self) -> u64

Absolute TSC-deadline value last written to IA32_TSC_DEADLINE.

Source

pub fn arm(&mut self, initial_count: u32)

Programs the timer with initial_count (0 disables it).

In one-shot and periodic modes this loads the current count and starts counting. In TSC-deadline and reserved modes the register is stored but the count-based timer stays stopped, matching the architectural rule that the initial count is ignored in TSC-deadline mode.

Source

pub fn set_tsc_deadline(&mut self, deadline: u64)

Writes the IA32_TSC_DEADLINE MSR.

A zero value disables the deadline. The value is absolute in model-TSC units; a deadline already in the past raises the LVT vector immediately (unless masked). Writes are ignored for the timer state unless the LVT entry is in TSC-deadline mode.

Source

pub fn set_tsc(&mut self, tsc: u64)

Aligns the model TSC with a caller-known absolute value.

The model starts at zero and is normally advanced by Self::advance; this hook lets a caller that knows the guest TSC epoch seed it once, so absolute IA32_TSC_DEADLINE values can be interpreted.

Source

pub fn advance(&mut self, cycles: u64)

Advances the timer by cycles APIC timer input units.

The caller passes the elapsed time already expressed in APIC timer input units (bus ticks before the divide). Count-based modes divide it by the configured divide value and decrement the current count; TSC-deadline mode compares the model TSC with the programmed deadline. Expiry raises the LVT vector through the IRR, except when the LVT entry is masked.

This is the raw model helper, kept for tests and for callers that already work in bus ticks. A caller holding host TSC cycles and a TSC frequency must use Self::advance_tsc, which performs the conversion.

Source

pub const fn apic_bus_hz(&self) -> u64

Nominal APIC timer bus frequency, in hertz.

Source

pub fn set_apic_bus_hz(&mut self, bus_hz: u64)

Changes the nominal APIC timer bus frequency.

The conversion remainder is reset because its unit depends on the bus frequency. A zero value disables the count-based conversion of Self::advance_tsc (the model TSC still advances).

Source

pub fn advance_tsc(&mut self, cycles: u64, tsc_hz: u64)

Advances the model by host TSC cycles, converting to APIC ticks.

tsc_hz is the host TSC frequency in hertz. The count-based timer is decremented by:

bus_ticks = (cycles * apic_bus_hz + remainder) / tsc_hz

where remainder is carried across calls so that the average conversion rate stays exact even when a call spans less than one bus tick. The model TSC used by TSC-deadline mode advances by the raw cycles, without conversion: a deadline is an absolute TSC value.

A zero tsc_hz or a zero bus frequency disables the count conversion (the model TSC still advances and deadlines are still detected), so a caller without a detected frequency degrades gracefully instead of dividing by zero. Arithmetic saturates.

Source

fn advance_count(&mut self, cycles: u64)

Decrements the count-based timer by the divided elapsed cycles.

Source

fn raise_timer_vector(&mut self)

Raises the LVT vector unless the entry is masked.

Source

fn expire_tsc_deadline(&mut self)

Completes a TSC-deadline expiry.

Source

fn write_lvt_timer(&mut self, value: u32)

Applies a write to the LVT timer entry, keeping the timer state consistent with the newly selected mode.

Source

pub fn mmio_read(&self, offset: usize) -> u32

Reads an MMIO register (address relative to the APIC page).

Unimplemented offsets return 0 (guest access tolerated).

Source

pub fn mmio_write(&mut self, offset: usize, value: u32)

Writes an MMIO register. Unimplemented offsets are ignored.

Source

fn write_icr_low(&mut self, value: u32)

Handles an ICR-low write: fixed IPI to self or NMI.

Source

pub fn x2apic_read(&self, msr: u32) -> Option<u64>

Reads an x2APIC MSR. Returns None outside the 0x800..=0x8FF range.

Source

pub fn x2apic_write(&mut self, msr: u32, value: u64) -> bool

Writes an x2APIC MSR. Returns false if the MSR is not modeled.

Trait Implementations§

Source§

impl Clone for LocalApic

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 LocalApic

Source§

impl Debug for LocalApic

Source§

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

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

impl Eq for LocalApic

Source§

impl PartialEq for LocalApic

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 LocalApic

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.