Skip to main content

AtomicSporadicState

Struct AtomicSporadicState 

Source
pub struct AtomicSporadicState {
    pub budget_remaining_us: AtomicU32,
    pub last_refill_ms: AtomicU32,
    pub budget_capacity_us: u32,
    pub period_us: u32,
    pub overrun_count: AtomicU32,
    pub last_overrun_us: AtomicU32,
}
Expand description

Phase 110.E.b — atomic sporadic-server state for ISR-driven refill. ISR / timer-thread context calls refill_thunk to top up the budget; spin_once reads atomically without any &mut access.

Replaces the polled-clock SporadicState shape on platforms with a PlatformTimer impl. The Executor still keeps the legacy SporadicState path active on feature = "std" so the transition is non-breaking.

Fields§

§budget_remaining_us: AtomicU32§last_refill_ms: AtomicU32

Wraps every ~50 days at ms resolution; saturates per tick’s monotonic-clock contract. portable-atomic provides AtomicU32 even on RISC-V riscv32imc / Cortex-M0+ that lack native 32-bit atomics.

§budget_capacity_us: u32§period_us: u32§overrun_count: AtomicU32

Phase 110.E.b — cumulative count of dispatched callbacks whose measured wall-clock runtime exceeded the SC’s budget_us. Bumped by the per-callback runtime closure inside Executor::spin_once (std-only — the no_std fallback continues to use the polled SporadicState path without per-callback overrun accounting). Cooperative single-thread dispatch can’t preempt a runaway callback, so this counter is the diagnostic signal — the design’s oneshot-IRQ-and- cancel pattern is structurally equivalent for non-preemptive callbacks, and last_overrun_us carries the worst-case observation for tuning. Both reset by clear_overrun_stats.

§last_overrun_us: AtomicU32

Phase 110.E.b — most recent dispatch’s overrun amount (measured_us - budget_us). 0 when no overrun has been observed since the last clear_overrun_stats. Used by monitoring code that wants to size the budget against worst-case observed runtime.

Implementations§

Source§

impl AtomicSporadicState

Source

pub const fn new(budget_us: u32, period_us: u32) -> Self

Source

pub fn record_overrun(&self, overrun_us: u32)

Record one overrun: callback measured runtime exceeded the SC’s budget_us. Bumps overrun_count + stores the absolute overrun amount in last_overrun_us. Called from the per-callback runtime closure inside Executor::spin_once.

Source

pub fn clear_overrun_stats(&self)

Reset both overrun statistics. Useful when tuning the budget across windows (monitoring code logs + clears periodically).

Source

pub fn has_budget(&self) -> bool

Read the budget atomically; spin_once consults this to decide whether to skip the SC’s entries this cycle.

Source

pub fn consume(&self, us: u32)

Saturating subtract — used by spin_once after dispatching a callback bound to this SC.

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
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.