Course Details
What is real-time? Hard vs Soft RTOS
Foundations of Real-Time Systems
Defining “Real-Time”
The most common misconception in computing is that “real-time” simply means “fast.” In engineering, real-time is defined by timeliness and predictability. A real-time system is one where the correctness of an operation depends not only on the logical result but also on the *time* at which the result is produced. Deadlines are absolute constraints.
Characteristics of Real-Time Systems
- Timeliness: The ability to respond to events within defined deadlines.
- Predictability (Determinism): The system’s behavior (especially timing) is consistent and can be mathematically analyzed.
- Responsiveness: The ability to transition quickly from idle state to processing state upon an event.
- Reliability/Dependability: Critical for safety-of-life systems.
The Spectrum of Real-Time Systems
Hard Real-Time Systems
In hard real-time systems, an absolute deadline exists. Missing a deadline is synonymous with total system failure, potentially leading to catastrophic consequences such as loss of life, severe injury, or destruction of the environment.
- Examples: Anti-lock Braking Systems (ABS), pacemakers, avionics flight control.
- Constraints: Must be 100% deterministic; worst-case execution time (WCET) must be proven.
Soft Real-Time Systems
Soft real-time systems have deadlines, but missing them occasionally causes degraded performance rather than system failure. There is a “value” to the computation that diminishes as time passes, but the system remains functional.
- Examples: Multimedia streaming, graphical user interfaces, web server response times.
- Constraints: Statistical performance (e.g., “99% of frames must be rendered on time”) is often acceptable.
Firm Real-Time Systems
A midpoint where missing a deadline renders the result useless, but the failure is not catastrophic. Example: A radar system updating a track. If the update is late, the data is stale and discarded, but the overall system survives.
The Role of an RTOS
Why an RTOS?
Standard OSs (like Windows or Linux) are designed for throughput and fairness; they cannot guarantee that a high-priority task will execute within a specific microsecond. An RTOS is designed specifically for determinism.
Core Components of an RTOS
- Scheduler: The brain of the RTOS. It decides which task runs next based on priorities.
- Task Management: Creating, deleting, and managing the state of concurrent threads/tasks.
- Inter-Task Communication (ITC): Mechanisms like Semaphores, Mutexes, and Message Queues that allow tasks to synchronize and share data safely.
Determinism and Scheduling
Preemptive vs. Non-Preemptive Scheduling
- Non-Preemptive (Cooperative): A task runs until it voluntarily yields the CPU. Simple to implement, but one runaway task can starve the entire system.
- Preemptive: The scheduler can forcefully stop a low-priority task to run a higher-priority one. Necessary for hard real-time systems.
Common Real-Time Problems
- Priority Inversion: A high-priority task is blocked by a lower-priority task holding a resource. Modern RTOSes use “Priority Inheritance” to solve this.
- Jitter: The variation in latency for a periodic task. Minimizing jitter is a primary goal of RTOS configuration.
- Deadlock: Two tasks waiting for resources held by each other.
Designing for Predictability
Worst-Case Execution Time (WCET)
In real-time design, you cannot optimize for the “average” case; you must optimize for the absolute worst-case scenario. Measuring WCET involves rigorous testing, code path analysis, and understanding hardware-level interactions (caches, pipeline stalls).
Debugging Real-Time Systems
Traditional debugging (breakpoints) is often intrusive, meaning the act of debugging changes the system timing, causing the bug to disappear (the “Heisenbug” phenomenon). Real-time developers prefer non-intrusive tools like hardware trace interfaces or high-speed telemetry logging.