Skip to main content

Crate rtsched

Crate rtsched 

Source
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

  • CfsThread uses a red-black-tree run queue ordered by virtual runtime.
  • RtThread uses an RtKTimer entry 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_tick advances timers and requests dispatch from the target-specific context-switch path.
  • MessageQueue transfers 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§

rtsched_println

Structs§

AlignedStack
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.
BinarySemaphore
A no-heap binary semaphore.
CfsSchedInfo
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.
CfsThreadBuilder
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.
CountingSemaphore
A no-heap counting semaphore.
HostPlatform
Host platform used by native tests and documentation builds.
IdleThread
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.
InitialThreadContext
Initial thread context produced by a platform stack initializer.
MessageQueue
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.
MutexGuard
RAII guard returned by Mutex::lock and Mutex::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.
RtThreadBuilder
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
SchedIsrTiming
DWT-cycle timing for the SysTick-to-PendSV path.
ThreadCtx
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.
ThreadHandle
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.
ThreadId
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.
ThreadStart
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.
TraceCounters
Saturating counters for common scheduler events.
TraceThread
Snapshot of a scheduler-visible thread for trace events.

Enums§

MessageQueueStatus
Non-success status returned by a message queue operation.
MutexError
Error returned by mutex operations.
SemaphoreError
Error returned by semaphore operations.
SyncType
Synchronization primitive type encoded in a waiting thread’s event tag.
ThreadKind
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.
ThreadRef
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.
ThreadSpawnError
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.
ThreadState
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.
TraceEvent
Scheduler events emitted by the tracing hook.
WaitQueueError

Constants§

VERSION
Crate version taken from Cargo metadata at compile time.

Traits§

ContextSwitchPort
Provides the architecture context-switch entry points.
CriticalSectionPort
Protects scheduler globals from interrupt or test-thread interleaving.
CycleCounterPort
Provides a cycle counter used for elapsed-time diagnostics.
Platform
Complete scheduler platform contract.
SchedulerTimerPort
Provides the reloadable timer used by the kernel timer queue.
ThreadStackPort
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 msec milliseconds.
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_cycles and get_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 f for each ktimer with its name and remaining ticks. This is similar to traverse_ktimer_queue but 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§

DefaultPlatform
ThreadEntry
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