Professional Documents
Culture Documents
4.1 Introduction
4.2 Context switching mechanisms
4.3 Scheduling policies
4.3.1 Preemptive Priority-Based Scheduling
4.3.2 Round-Robin Scheduling
4.4 Message passing and shared memory communications
4.4.1 Shared Memory with Mutexes
4.4.2 Shared Memory with Interrupt Locks
4.4.3 Shared Memory with Preemption Locks
4.5 Inter-process communication
4.1 INTRODUCTION
Embedded OS
Why an OS at all?
Same reasons why we need one for a traditional computer.
it serves as the core software that manages and controls the
hardware resources of the computer
Not all services provided by an operating system are needed
for every device or system.
REASONS WHY AN OPERATING SYSTEM IS NEEDED IN
EMBEDDED SYSTEMS
Here are some reasons why an operating system is needed in
embedded systems,
Resource Management:
can vary depending on the specific use case, hardware capabilities, and intended functionality of the device.
Large variety of requirements and environments:
1. Critical applications with high functionality (e.g., medical applications, space shuttle, process automation):
- Reliability and fault tolerance:These applications require high levels of reliability to ensure safe and consistent
operation. The operating system should be designed with fault-tolerant mechanisms, real-time capabilities, and rigorous
testing to minimize the risk of failures.
- Deterministic performance:Real-time performance guarantees are essential for critical applications where timing
precision is crucial. The operating system should provide deterministic behavior to meet strict timing requirements.
- Security: Robust security features are critical to protect sensitive data and prevent unauthorized access. The
operating system should include strong authentication, encryption, access controls, and secure communication
protocols.
2. Critical applications with small functionality (e.g., Antilock Braking System (ABS), pacemaker):
- Resource efficiency: These applications have limited hardware resources and require an operating system that is
lightweight and optimized for low-power consumption. The operating system should be tailored to run efficiently on
constrained devices without sacrificing performance.
- Real-time responsiveness: Real-time capabilities are essential for critical applications with small functionality to
ensure timely and precise responses to external stimuli or events. The operating system should provide deterministic
behavior and low latency for critical operations.
3. Less critical applications with varying functionality (e.g., smartphone, smart card, microwave oven):**
- Flexibility and scalability: Operating systems for less critical applications should be flexible and scalable to
accommodate a wide range of functionalities and usage scenarios. Modularity and customization options can allow
users to adapt the system to their specific needs.
- User experience: Emphasizing user-friendly interfaces, responsiveness, and intuitive interactions can enhance the
usability of the operating system for consumer-oriented devices like smartphones and smart cards.
- Resource management:Efficient resource utilization and performance optimization are important for less critical
applications to ensure smooth operation without unnecessary resource consumption.
4.1 INTRODUCTION
Why is a desktop OS not suited?
Monolithic kernel is too feature rich: In a monolithic kernel
architecture, the entire operating system, including device drivers,
file system management, memory management, and system call
interfaces, is implemented as a single, large, and cohesive unit.
Monolithic kernel is not modular, fault-tolerant, configurable,
modifiable, … .(This lack of modularity can make it challenging
to isolate and modify specific components without affecting the
entire system.)
Takes too much memory space.
It is often too resource hungry in terms of computation time.
Not designed for mission-critical applications.
Timing uncertainty too large.
4.1 INTRODUCTION
What is an RTOS?
An RTOS is a class of operating systems that are intended for real
time-applications
What is a real time application?
A real time application is an application that guarantees both
correctness of result and the added constraint of meeting a deadline
So what is an RTOS?
An operating system which follows the Real Time criteria.
Efficiency, Predictability and Timeliness –important
All components of an RTOS must have these properties.
Some tasks which may delay things:
Interrupt Processing, Context Switching, Inter-task communication,
4.1 INTRODUCTION
So what makes an RTOS special?
An RTOS will provide facilities to guarantee deadlines will be met
An RTOS will provide scheduling algorithms in order to enable
deterministic behavior in the system
An RTOS is valued more for predictability than throughput
Design Philosophies
Some of the design philosophies of an RTOS are with respect to:
Scheduling
Memory allocation
Inter task communication
Interrupt handlers
4.1 INTRODUCTION
In some applications, an RTOS comprises only a
kernel, which is the core supervisory software
that provides minimal logic, scheduling, and
resource-management algorithms.
Every RTOS has a kernel.
an RTOS can be a combination of various
modules, including the kernel, a file system,
networking protocol stacks, and other
components required for a particular application,
as illustrated at a high level in Figure 4.1.
4.1 INTRODUCTION
Figure 4.1: High-level view of an RTOS, its kernel, and other components found in embedded systems .
4.2 CONTEXT SWITCHING MECHANISMS
The time it takes for the scheduler to switch from one task to
another is the context switch time.
It is relatively insignificant compared to most operations that a
task performs.
If an application’s design includes frequent context switching,
however, the application can incur unnecessary performance
overhead.
Every time an application makes a system call, the scheduler
has an opportunity to determine if it needs to switch contexts.
When the scheduler determines a context switch is necessary,
it relies on an associated module, called the dispatcher, to
make that switch happen.
4.2 CONTEXT SWITCHING MECHANISMS
The dispatcher is the part of the scheduler that performs
context switching and changes the flow of execution.
At any time an RTOS is running, the flow of execution,
also known as flow of control, is passing through one of
three areas: through an application task, through an ISR, or
through the kernel.
When a task or ISR makes a system call, the flow of
control passes to the kernel to execute one of the system
routines provided by the kernel.
When it is time to leave the kernel, the dispatcher is
responsible for passing control to one of the tasks in the
user’s application.
4.3 SCHEDULING POLICIES
Advantages:
- Supports task prioritization based on criticality or importance.
- Ensures that high-priority tasks are executed promptly.
- Helps meet real-time requirements by allowing time-critical tasks to preempt lower-priority
tasks.
Disadvantages:
- Priority inversion issues may occur, where a lower-priority task holds a resource needed by
a higher-priority task.
- Priority inversion can be mitigated using techniques like priority inheritance or priority
ceiling protocols.
4.3.1 PREEMPTIVE PRIORITY-BASED SCHEDULING
Advantages:
- Provides fair allocation of CPU time among tasks.
- Prevents tasks from starving by ensuring that each task gets a chance to run.
- Simple and easy to implement.
Disadvantages:
- May not be suitable for real-time systems with strict timing requirements.
- May lead to inefficiencies if tasks have varying execution times or resource
4.3.2 ROUND-ROBIN SCHEDULING
With time slicing, each task executes for a defined interval, or time slice, in an
ongoing cycle, which is the round robin.
A run-time counter tracks the time slice for each task, incrementing on every
clock tick.
When one task’s time slice completes, the counter is cleared, and the task is
placed at the end of the cycle.
4.4 MESSAGE PASSING AND SHARED MEMORY COMMUNICATIONS
Message passing supports explicit data transfer
between processes; hence, it does not require a
shared memory and lends itself well to be
extended to distributed systems.
This inter-process communication method
provides for two primitives:
The SEND primitive sends a message to a given
destination.
Symmetrically, RECEIVE receives a message from a
given source.
4.4 MESSAGE PASSING AND SHARED MEMORY COMMUNICATIONS
Communication can be signal-centric, data-
centric, or both.
In signal-centric communication, all necessary
information is conveyed within the event signal
itself.
In data-centric communication, information is
carried within the transferred data.
When the two are combined, data transfer
accompanies event notification.
4.4 MESSAGE PASSING AND SHARED MEMORY COMMUNICATIONS
Figure 4.8: ISR-to-task resource synchronization- shared memory guarded by interrupt lock
4.4.3 SHARED MEMORY WITH PREEMPTION LOCKS
In this design pattern, two tasks transfer data to each other using
shared memory, as shown in Figure 4.9.
Each task is responsible for disabling preemption before accessing
the shared memory.
Unlike using a binary semaphore or a mutex lock, no waiting is
involved when using a preemption lock for synchronization.