Expand description
Runtime scheduler primitives for no_std embedded applications.
rtsched provides the core pieces needed to create, queue, block, wake, and
context-switch application threads on a single microcontroller core. It
combines CFS-style background scheduling with soft real-time scheduling built
on kernel timers ordered by deadline.
Board crates own the hardware setup: clocks, timer interrupts,
architecture-specific context-switch entry points, stack storage, and
concrete thread storage. A typical board initializes the timer queue with
init_ktimer_queue, configures CFS with init_cfs, creates
CfsThread and RtThread values with their builders, and starts the
idle thread with spawn_main_thread.
The crate is no_std for embedded builds. Host-only test support provides
scheduler state serialization so the same core data structures can be
exercised by unit tests.
§Scheduling Model
CfsThreaduses a red-black-tree run queue ordered by virtual runtime.RtThreaduses anRtKTimerentry for deadline-based scheduling.- Waiting threads move through a wait queue and can be resumed by timer expiry or scheduler wake-up paths.
handle_sched_tickadvances timers and requests dispatch from the target-specific context-switch path.MessageQueuetransfers copied FIFO messages between threads, with bounded inline storage and blocking or nonblocking send/receive operations.
§Safety
This crate exposes low-level scheduler entry points that operate on raw
pointers, intrusive queue links, global scheduler state, and
architecture-specific stack frames. Public unsafe functions document their
caller obligations individually. Board code must ensure thread and stack
storage outlives all scheduler use and that initialization happens before
scheduler interrupts can observe the global state.
Macros§
Structs§
- Aligned
Stack - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. 8-byte aligned stack storage for platform thread contexts.
- Binary
Semaphore - A no-heap binary semaphore.
- CfsSched
Info - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- CfsThread
- Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Thread control block for CFS-scheduled threads.
- CfsThread
Builder - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- Counting
Semaphore - A no-heap counting semaphore.
- Host
Platform - Host platform used by native tests and documentation builds.
- Idle
Thread - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Thread control block for the scheduler idle fallback.
- Initial
Thread Context - Initial thread context produced by a platform stack initializer.
- Message
Queue - A fixed-capacity FIFO message queue with multiple producers and consumers.
- Mutex
- A no-heap, non-recursive scheduler mutex protecting a value of type
T. - Mutex
Guard - RAII guard returned by
Mutex::lockandMutex::try_lock. - RtKTimer
- RtThread
- Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Thread control block for RT-scheduled threads.
- RtThread
Builder - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- RtTiming
- Sched
IsrTiming - DWT-cycle timing for the SysTick-to-PendSV path.
- Thread
Ctx - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Common scheduler-visible thread context.
- Thread
Handle - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Opaque reference to a scheduler thread.
- Thread
Id - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Scheduler-assigned thread identifier.
- Thread
Start - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- Trace
Counters - Saturating counters for common scheduler events.
- Trace
Thread - Snapshot of a scheduler-visible thread for trace events.
Enums§
- Message
Queue Status - Non-success status returned by a message queue operation.
- Mutex
Error - Error returned by mutex operations.
- Semaphore
Error - Error returned by semaphore operations.
- Sync
Type - Synchronization primitive type encoded in a waiting thread’s event tag.
- Thread
Kind - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Scheduler-visible concrete thread kind.
- Thread
Ref - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- Thread
Spawn Error - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Validation failures that can be detected before a thread is spawned.
- Thread
State - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Execution state for a scheduled thread.
- Trace
Event - Scheduler events emitted by the tracing hook.
- Wait
Queue Error
Constants§
- VERSION
- Crate version taken from Cargo metadata at compile time.
Traits§
- Context
Switch Port - Provides the architecture context-switch entry points.
- Critical
Section Port - Protects scheduler globals from interrupt or test-thread interleaving.
- Cycle
Counter Port - Provides a cycle counter used for elapsed-time diagnostics.
- Platform
- Complete scheduler platform contract.
- Scheduler
Timer Port - Provides the reloadable timer used by the kernel timer queue.
- Thread
Stack Port - Builds the synthetic stack frame needed to start a scheduler thread.
Functions§
- clear_
trace_ fn - Remove any registered trace callback.
- current_
rt_ thread_ runtime - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- current_
thread - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Return a handle to the thread currently selected by the scheduler.
- current_
thread_ id - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Return the identifier of the thread currently selected by the scheduler.
- dwt_
cycle_ count - get_
elapse_ cycles - Return elapsed DWT cycles since the last DWT elapsed-counter reset.
- get_
elapse_ msec - Return elapsed milliseconds since the last DWT elapsed-counter reset.
- get_
elapse_ msec_ since - handle_
sched_ tick - Handle one scheduler tick and request ktimer dispatch.
- init_
cfs ⚠ - Initialize the CFS scheduler state and enqueue its scheduler timer.
- init_
dwt_ cycle_ counter - init_
ktimer_ ⚠queue - Initialize the global ktimer and wait-timer state.
- is_
active_ ktimer - Return whether the named kernel timer is currently active.
- mark_
sched_ tick_ to_ pendsv_ start - Mark the beginning of a SysTick interrupt for SysTick-to-PendSV timing.
- msleepyi
- Re-exports of core scheduler primitives for convenient use in application code.
Re-exports of core scheduler primitives for convenient use in application code.
Re-exports of core scheduler primitives for convenient use in application code.
Suspend the running thread for
msecmilliseconds. - next_
ktimer_ reload - register_
idle_ ⚠thread - Register the thread that should run when no normal work is runnable.
- reset_
elapse_ counter - Reset the baseline used by
get_elapse_cyclesandget_elapse_msec. - reset_
sched_ tick_ to_ pendsv_ max_ ticks - reset_
sched_ tick_ to_ pendsv_ min_ max_ ticks - reset_
sched_ tick_ to_ pendsv_ min_ ticks - reset_
sched_ tick_ to_ pendsv_ timing - reset_
trace_ counters - Reset scheduler trace counters to zero.
- sched_
tick_ to_ pendsv_ timing - set_
print_ fn - set_
trace_ fn - Register a trace callback for scheduler events.
- spawn_
main_ ⚠thread - Initialize the idle thread and spawn it as the first scheduler thread.
- sys_
clk_ freq - ticks_
per_ ms - trace_
counters - Return the current scheduler trace counters.
- traverse_
idle_ thread_ fn - traverse_
ktimer_ queue - traverse_
ktimer_ queue_ fn - Traverse the ktimer queue and invoke
ffor each ktimer with its name and remaining ticks. This is similar totraverse_ktimer_queuebut allows the caller to handle formatting/output (for example, writing to UART). - traverse_
run_ queue_ fn - Visit scheduler-visible CFS threads without exposing raw traversal cursors.
- traverse_
wait_ queue_ fn - Visit blocked threads without exposing raw traversal cursors.
- update_
sys_ clk_ freq - yieldyi
- Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Cooperatively yield the CPU from the running RT thread to the next scheduled left-most timer in the KTimer rbtree.
Type Aliases§
- Default
Platform - Thread
Entry - Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code. Re-exports of core scheduler primitives for convenient use in application code.
- TraceFn