UNIT 3: Concept and Fundamentals of RTOS
The RTOS kernel is the core component of a Real-Time Operating System (RTOS). It's the heart of the
system, responsible for managing all other parts and ensuring the system meets its real-time requirements.
Key Functions of an RTOS Kernel:
● Task Scheduling:
○ Prioritization: Assigns priorities to tasks based on their criticality and deadlines.
○ Context Switching: Efficiently switches the CPU between running tasks.
○ Scheduling Algorithms: Implements algorithms like Rate Monotonic, Earliest Deadline
First, or Round Robin to determine task execution order.
● Interrupt Handling:
○ Interrupt Service Routines (ISRs): Manages the execution of ISRs in a timely and
efficient manner.
○ Interrupt Latency: Minimizes the time between an interrupt occurring and the start of
the ISR.
● Memory Management:
○ Allocation: Allocates and deallocates memory for tasks and other system components.
○ Protection: Ensures memory access rights are enforced to prevent unauthorized access.
● Inter-Process Communication (IPC):
○ Provides mechanisms for tasks to communicate and synchronize:
■ Semaphores: Control access to shared resources.
■ Mutexes: Prevent race conditions and ensure mutual exclusion.
■ Message Queues: Allow tasks to exchange data asynchronously.
■ Signals: Notify tasks of events.
● Resource Management:
○ Manages access to shared resources:
■ Timers: Provides timing services for tasks.
■ Peripherals: Controls access to hardware devices (e.g., sensors, actuators).
● System Calls:
○ Provides a set of system calls that allow tasks to interact with the kernel and request
services.
Characteristics of an RTOS Kernel:
● Small Footprint: RTOS kernels are typically designed to be compact and efficient, suitable for
embedded systems with limited resources.
● Deterministic Behavior: Predictable response times and consistent performance are crucial for
real-time systems.
● Real-time Capabilities: Prioritizes time-critical tasks and ensures that deadlines are met.
Examples of RTOS Kernels:
● FreeRTOS: A popular open-source RTOS kernel known for its simplicity and efficiency.
● VxWorks: A widely used commercial RTOS for industrial and aerospace applications.
UNIT 3: Concept and Fundamentals of RTOS
● QNX: A microkernel-based RTOS known for its reliability and safety features.
● μC/OS-II: A royalty-free RTOS for small embedded systems.
The RTOS kernel plays a vital role in the success of any real-time system. By providing a robust and
efficient foundation, it enables the development of reliable and predictable embedded applications.
TIME SERVICES
Time services are an essential feature of RTOS that provide accurate and reliable timing services to real
time application.
Here are some services typically provided:
1. Tick Timer
§ A tick timer is a periodic interrupt generated by RTOS, which allow the
operating system to keep track of time.
§ The tick timer is typically generated at a fixed interval, such as every
millisecond and is used by the RTOS scheduler to determine when to switch
tasks.
2. Clocks
§ An RTOS typically provides a clock function that return the current system
time in a specific format, such as hours, minutes, and seconds.
§ The system time is used by application to timestamp events or to schedule
tasks.
3. Timers:
§ Timers are used to schedule tasks or events to occur at a specific time or after s
specific period.
§ The RTOS provides a timer function that allows an application to
4. Delays:
§ An RTOS provides a delay function that allows and application to paused
execution for a specified period
5. Time synchronization
UNIT 3: Concept and Fundamentals of RTOS
SCHEDULING APPROACHES
1. Static table-driven approach:
A "static table-driven approach" in the context of an RTOS (Real-time Operating System) refers to a
scheduling method where the execution order of tasks is pre-determined and stored in a table at compile
time, meaning the system doesn't need to make dynamic calculations at runtime to decide which task to
run next, ensuring predictable and deterministic behavior crucial for real-time applications.
Advantages:
· Deterministic behavior: Provides highly predictable task execution, which is critical
for real-time systems where missing deadlines can lead to system failure.
· Efficiency: No runtime overhead for scheduling decisions as the schedule is already
pre-determined.
Disadvantages:
· Limited flexibility: Not suitable for scenarios with highly dynamic or unpredictable
task arrival patterns.
· Complex design process: Requires careful analysis and planning to create an efficient
and feasible static schedule.
Application:
ü Industrial control systems: Where machines need to perform specific actions at precise
intervals.
ü Flight control systems: Maintaining critical flight parameters within strict timing
constraints.
ü Robotics applications: Coordinating precise movements of robotic arms with
predictable timing.
2. Static priority-driven preemptive approach
A "static priority-driven preemptive approach" in an RTOS (Real-time Operating System) refers to a
scheduling method where each task is assigned a fixed priority at design time, and if a higher priority task
UNIT 3: Concept and Fundamentals of RTOS
becomes ready to execute, the currently running task is immediately interrupted and the higher priority
task takes over the CPU, ensuring time-critical tasks are always prioritized and executed promptly; this is
considered a static approach because the priorities of tasks do not change during runtime.
Advantages:
● Predictability:
○ Because priorities are fixed, the behavior of the system is highly predictable, which is
crucial for real-time applications.
● Responsiveness:
○ High-priority tasks can quickly interrupt lower-priority tasks, ensuring timely execution
of critical operations.
● Simplicity:
○ The scheduling algorithm is relatively simple to implement.
Disadvantages:
● Priority Inversion:
○ A high-priority task can be blocked by a lower-priority task if they share a resource.
● Starvation:
○ Low-priority tasks may be indefinitely delayed if high-priority tasks continuously arrive.
● Rigidity:
○ The static nature of the priorities can make it hard to adapt to changing system
conditions.
Applications:
● This approach is commonly used in hard real-time systems where deadlines must be strictly met,
such as:
○ Aerospace and defense systems
○ Automotive control systems
○ Industrial automation
3. Dynamic planning based approach RTOS
a "dynamic planning-based approach" in the context of a Real-Time Operating System (RTOS), we're
generally talking about scheduling algorithms that make decisions at runtime, adapting to changing
conditions. This is in contrast to static scheduling, where decisions are made beforehand.
Advantages:
UNIT 3: Concept and Fundamentals of RTOS
● Flexibility:
○ Dynamic scheduling can handle a wider range of real-time applications.
● Resource Utilization:
○ It can often achieve higher resource utilization compared to static scheduling.
Disadvantages:
● Complexity:
○ The algorithms can be complex to implement and analyze.
● Overhead:
○ Dynamic scheduling incurs runtime overhead, which can impact performance.
● Predictability:
○ In some cases, it can be harder to guarantee that all deadlines will be met.
Applications:
● Dynamic planning-based RTOS approaches are often used in:
○ Systems with unpredictable workloads.
○ Robotics and autonomous systems.
○ Multimedia applications.
○ Advanced control systems.
4. Dynamic best effort approach
A "dynamic best effort approach" in an RTOS (Real-Time Operating System) refers to a scheduling
strategy where the system attempts to execute tasks as quickly as possible based on their current priorities
and deadlines, but does not guarantee that all tasks will meet their deadlines, prioritizing responsiveness
even if it means occasionally missing deadlines in unpredictable situations; essentially, the system will try
its best to meet deadlines but is not strictly bound to them, making it suitable for situations where some
flexibility is acceptable.
Key Characteristics:
● Flexibility:
○ The system can handle fluctuating workloads and unexpected events.
○ It's suitable for applications where the workload is unpredictable.
● Resource Optimization:
○ The focus is on maximizing the utilization of available resources.
○ The system aims to complete as many tasks as possible, even if some deadlines are
missed.
● Soft Real-Time:
UNIT 3: Concept and Fundamentals of RTOS
○ This approach is typically used in soft real-time systems, where occasional deadline
misses are acceptable. Examples include multimedia streaming or certain types of
network applications.
● Adaptive Scheduling:
○ The RTOS may employ algorithms that dynamically adjust task priorities or resource
allocations based on current conditions.
○ It might use heuristics or statistical methods to make scheduling decisions.
How it Differs from Hard Real-Time:
● In hard real-time systems, missing a deadline can have catastrophic consequences.
● Dynamic best-effort approaches prioritize flexibility and resource utilization over strict deadline
adherence.
Applications:
● Multimedia streaming: Where occasional frame drops are acceptable.
● Networked applications: Where some latency is tolerable.
● Certain types of control systems: Where occasional delays do not lead to critical failures.
Internal and External Interrupts
When you bring interrupts into the context of a Real-Time Operating System (RTOS), they take on a
critical role in ensuring timely and predictable responses to events. Here's how internal and external
interrupts are handled within an RTOS:
Key Role of Interrupts in RTOS:
● Real-time response:
○ RTOS are designed to handle time-critical tasks. Interrupts provide the mechanism for
immediate responses to events, ensuring that deadlines are met.
● Event-driven behavior:
○ Many RTOS applications are event-driven, meaning they react to external or internal
events.4 Interrupts are the primary way these events are signaled to the RTOS.
● Task management:
○ Interrupts can trigger task switching, allowing the RTOS to quickly switch to a
higher-priority task when an important event occurs.5
How RTOS Handles Interrupts:
1. Interrupt Service Routines (ISRs):
UNIT 3: Concept and Fundamentals of RTOS
○ When an interrupt occurs, the CPU jumps to a specific function called an ISR.6
○ In an RTOS, ISRs are typically kept short and efficient to minimize interrupt latency (the
time it takes to respond to an interrupt).7
○ ISRs often perform minimal processing and then signal the RTOS to handle the more
complex processing in a separate task.
2. Interrupt Handling and Task Scheduling:
○ The RTOS manages interrupt priorities and ensures that higher-priority interrupts are
handled first.8
○ ISRs can signal the RTOS to:
■ Wake up a waiting task.
■ Change the priority of a task.
■ Send a message to a task.
○ The RTOS scheduler then determines which task should run next based on its priority and
the current system state.9
3. Internal Interrupts in RTOS:
○ RTOS often use internal interrupts for timekeeping, task scheduling, and other internal
functions.10
○ For example, a timer interrupt might be used to trigger periodic task scheduling.
○ RTOS also use internal interrupts to handle software exceptions, such as memory access
violations.
4. External Interrupts in RTOS:
○ External interrupts are used to handle events from peripheral devices, such as sensors,
actuators, and communication interfaces.11
○ RTOS provide mechanisms for registering interrupt handlers and managing external
interrupt priorities.
○ Essentially, the RTOS creates a framework for the use of the hardware interrupt system.12
Important Considerations:
● Interrupt Latency:
○ In real-time systems, interrupt latency is critical. RTOS are designed to minimize
interrupt latency.13
● Interrupt Priorities:
○ RTOS allow you to assign priorities to interrupts, ensuring that the most critical events
are handled first.14
● Interrupt Context:
○ ISRs run in a special interrupt context, which has certain limitations.15 RTOS provide
mechanisms for safely transferring data and control between the interrupt context and
task context.16
In summary, RTOS leverage interrupts to create responsive and predictable systems. They provide a
structured way to handle both internal and external events, ensuring that critical tasks are executed on
time.