Skip to main content

Module deadlines

Module deadlines 

Source
Expand description

Periods, drift-corrected periodic wake, and CPU-budget enforcement (plan.md Phase 11).

Both are configured per task by id via set_period_us/ set_budget_us (wired up through crate::preempt::TaskHandle). period_us is consumed by wait_period, which a periodic task calls once per iteration instead of sleep_ms — the deadline is computed from the previous deadline, not now, so per-iteration jitter never accumulates into long-term drift (the same technique soak/drift_test already exercise for the timer queue itself). budget_us is checked every tick against the task’s accumulated busy time within the current period (via crate::exec_time); exceeding it raises crate::fault::FaultKind::BudgetExceeded through the normal fault policy (Panic or IsolateTask — no new fault-handling path needed).

Deadline/snapshot storage follows the exact pattern already established by crate::timer’s PTASK_DEADLINES (UnsafeCell array, unsafe impl Sync, every access under critical::enter) since RV32/ARMv7-M have no native 64-bit atomics.

Functions§

budget_us
period_us
set_budget_us
Configure task id’s per-period CPU budget (microseconds, estimated — see crate::exec_time::estimate_us_from_cycles). 0 disables budget enforcement for that task.
set_period_us
Configure task id’s period (microseconds). 0 disables wait_period for that task (it returns immediately).
wait_period
Block the calling preemptive task until its next period boundary. Drift-corrected: the deadline is previous_deadline + period, not now + period, so a task that occasionally runs a bit late never permanently shifts its schedule. No-op if the calling task has no period configured (set_period_us not called, or called with 0) or isn’t a preemptive task.