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 — seecrate::exec_time::estimate_us_from_cycles).0disables budget enforcement for that task. - set_
period_ us - Configure task
id’s period (microseconds).0disableswait_periodfor 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, notnow + 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_usnot called, or called with0) or isn’t a preemptive task.