Kyron Runtime Component Architecture#
Kyron Runtime Component Architecture
|
status: draft
security: YES
safety: QM
|
||||
Kyron Runtime
|
status: valid
security: YES
safety: QM
|
||||
Overview#
The Kyron runtime is a Rust async/await runtime. It is built from one or more
execution engines. Each engine has its own pool of async workers, which use a
work-stealing scheduler, and optional dedicated workers that keep a task on its thread.
The runtime also provides a safety worker, an I/O event loop, TCP/UDP networking,
timers and sleep, channels, select!, iceoryx2-based IPC, and the
#[kyron::main] attribute macro.
Static Architecture#
Kyron Runtime Static View
|
status: valid
security: YES
safety: QM
|
||||
The generated diagram above shows the interface operations of the executor core. The diagram below shows the parts of the component, one box per row of the table below, and their main dependencies. Dashed arrows are wake-ups through a task’s waker.
|
|||||
The runtime is structured into the following parts. Only the executor core is covered by component requirements so far, so only the executor core parts are linked to requirements. The other parts get their links when their requirements are added.
Part |
Responsibility |
|---|---|
Runtime ( |
|
Execution engine ( |
|
Scheduler ( |
Task representation, per-worker queues, work stealing between async workers, and routing of dedicated tasks to the queue of their dedicated worker. |
Workers ( |
Async workers, dedicated workers and the safety worker. Each one is an OS thread that polls the tasks assigned to it. |
I/O driver ( |
Registers OS file descriptors (sockets, iceoryx2 event fds) with the OS poller (POSIX
|
Networking ( |
|
IPC ( |
Async iceoryx2 event |
Time ( |
|
Channels and |
Single-producer single-consumer and broadcast channels, and the |
Safety API and safety worker ( |
|
Futures and common types ( |
|
Attribute macro (crate |
|
All parts use the queues, synchronisation and threading primitives of Kyron Foundation (comp__kyron_foundation).
Dynamic Architecture#
The three sequences below show how a task runs, how a task waits for I/O, and how the safety worker takes over the error handling of a safety task.
Task Life Cycle
|
status: valid
security: YES
safety: QM
|
||||
A task spawned on async worker A is stolen and run by async worker B.
Every async worker takes the tasks of its own queue in FIFO order. Every 16th task it moves a batch of tasks from the global queue into its own queue. A worker with an empty queue steals only while fewer than half of the async workers are searching; otherwise it parks. The limit on searching workers is rounded up and not strictly enforced: concurrent workers can exceed it briefly. |
|||||
I/O Wait and Wake
|
status: valid
security: YES
safety: QM
|
||||
A task reads from a socket that has no data yet. The same sequence applies to
The wait timeout is the next timer expiry, or none when another parked worker already waits for that expiry. Busy async workers also call the poller with a zero timeout every 32 tasks, so readiness is seen without a parked worker. A task spawned while a worker waits in the OS poller wakes that worker through the internal waker of the I/O driver. |
|||||
Safety Worker Error Handling
|
status: valid
security: YES
safety: QM
|
||||
A parent task spawns a safety task, and the safety task fails. Calling the safety API from a
dedicated worker is a non-recoverable error. Without a safety worker
(
A non-recoverable error logs the error and panics ( |
|||||
Interfaces#
Kyron Runtime API
|
status: valid
security: NO
safety: QM
|
||||
The public Rust API of the runtime for building engines and runtimes, entering the runtime and spawning tasks. |
|||||
kyron::runtime::RuntimeBuilder::new
|
status: valid
security: NO
safety: QM
|
||||
Create a runtime builder without engines. Defined in |
|||||
kyron::runtime::RuntimeBuilder::with_engine
|
status: valid
security: NO
safety: QM
|
||||
Add an execution engine to the runtime. Defined in |
|||||
kyron::runtime::RuntimeBuilder::build
|
status: valid
security: NO
safety: QM
|
||||
Build the runtime from its execution engines. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::new
|
status: valid
security: NO
safety: QM
|
||||
Create an execution engine configuration. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::workers
|
status: valid
security: NO
safety: QM
|
||||
Set the number of async workers. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::task_queue_size
|
status: valid
security: NO
safety: QM
|
||||
Set the size of the task queue of each async worker. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::thread_priority
|
status: valid
security: NO
safety: QM
|
||||
Set the OS priority of the async workers. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::thread_affinity
|
status: valid
security: NO
safety: QM
|
||||
Set the CPU affinity of the async workers. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::thread_scheduler
|
status: valid
security: NO
safety: QM
|
||||
Set the OS scheduler type of the async workers. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::thread_stack_size
|
status: valid
security: NO
safety: QM
|
||||
Set the stack size of the async workers. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::enable_safety_worker
|
status: valid
security: NO
safety: QM
|
||||
Enable the safety worker of the engine. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::safety_worker_task_queue_size
|
status: valid
security: NO
safety: QM
|
||||
Set the task queue size of the safety worker. Defined in |
|||||
kyron::runtime::ExecutionEngineBuilder::with_dedicated_worker
|
status: valid
security: NO
safety: QM
|
||||
Add a dedicated worker to the engine. Defined in |
|||||
kyron::runtime::Runtime::block_on
|
status: valid
security: NO
safety: QM
|
||||
Run a future to completion on the default engine, blocking the current thread. Defined in |
|||||
kyron::runtime::Runtime::block_on_engine
|
status: valid
security: NO
safety: QM
|
||||
Run a future to completion on a specified engine, blocking the current thread. Defined in |
|||||
kyron::runtime::Runtime::spawn
|
status: valid
security: NO
safety: QM
|
||||
Start a future asynchronously on the default engine. Defined in |
|||||
kyron::runtime::Runtime::spawn_in_engine
|
status: valid
security: NO
safety: QM
|
||||
Start a future asynchronously on a specified engine. Defined in |
|||||
kyron::runtime::Runtime::shutdown
|
status: valid
security: NO
safety: QM
|
||||
Stop all engines and their worker threads. Defined in |
|||||
kyron::spawn
|
status: valid
security: NO
safety: QM
|
||||
Spawn a task on the async workers. Defined in |
|||||
kyron::spawn_from_boxed
|
status: valid
security: NO
safety: QM
|
||||
Spawn an already boxed task on the async workers. Defined in |
|||||
kyron::spawn_from_reusable
|
status: valid
security: NO
safety: QM
|
||||
Spawn a reusable task on the async workers. Defined in |
|||||
kyron::spawn_on_dedicated
|
status: valid
security: NO
safety: QM
|
||||
Spawn a task on a dedicated worker. Defined in |
|||||
kyron::spawn_from_boxed_on_dedicated
|
status: valid
security: NO
safety: QM
|
||||
Spawn an already boxed task on a dedicated worker. Defined in |
|||||
kyron::spawn_from_reusable_on_dedicated
|
status: valid
security: NO
safety: QM
|
||||
Spawn a reusable task on a dedicated worker. Defined in |
|||||
kyron::JoinHandle (Future)
|
status: valid
security: NO
safety: QM
|
||||
Await the completion and the result of a spawned task. Defined in |
|||||
kyron::JoinHandle::abort
|
status: valid
security: NO
safety: QM
|
||||
Abort a spawned task cooperatively. Defined in |
|||||
kyron::futures::yield_now::yield_now
|
status: valid
security: NO
safety: QM
|
||||
Give control back to the worker so that other queued tasks run first. Defined in
|
|||||
Further Interfaces#
The following public interfaces have no component requirements yet. They are described at the interface level only. Their operations and code links are added together with their requirements. The contract of each type and function is documented in its rustdoc.
Kyron Networking API
|
status: valid
security: YES
safety: QM
|
||||
|
|||||
Kyron OS I/O Layer API
|
status: valid
security: YES
safety: QM
|
||||
|
|||||
Kyron Futures and Common Types
|
status: valid
security: NO
safety: QM
|
||||
|
|||||
Kyron I/O API
|
status: valid
security: YES
safety: QM
|
||||
|
|||||
Kyron IPC API
|
status: valid
security: YES
safety: QM
|
||||
|
|||||
Kyron Time API
|
status: valid
security: NO
safety: QM
|
||||
|
|||||
Kyron Channels API
|
status: valid
security: NO
safety: QM
|
||||
|
|||||
Kyron Safety API
|
status: valid
security: NO
safety: QM
|
||||
|
|||||
Kyron Main Macro
|
status: valid
security: NO
safety: QM
|
||||
|
|||||
Interface Operations Without Code Link#
Every interface operation is linked to its implementation by a req-Id tag in the code. The
table lists the operations whose tag is missing; it is empty when the architecture and the
code are consistent.
No needs passed the filters