Unit Ii
Unit Ii
Introduction
Definition: An operating system designed to handle events or data as they
occur, providing timely and predictable responses.
Key Features:
RTOS Architecture:
For simpler applications, RTOS is usually a kernel but as complexity
facilities, device I/Os are includes in addition to the kernel. The general
Monolithic kernel
Monolithic kernels are part of Unix-like operating systems like Linux, FreeBSD
etc. A monolithic kernel is one single program that contains all of the code
necessary to perform every kernel related task. It runs all basic system
services (i.e. process and memory management, interrupt handling and I/O
communication, file system, etc) and provides powerful abstractions of the
Microkernel
other functions such as running the hardware processes are not handled
directly by microkernels. Thus, micro kernels provide a smaller set of simple
unaffected even if the servers failed (i.e.File System). Microkernels are part
of the operating systems like AIX, BeOS, Mach, Mac OS X, MINIX, and QNX.
Etc
Hybrid Kernel
swiftly than it would were it in user space. These are part of the operating
systems such as Microsoft Windows NT, 2000 and XP. DragonFly BSD, etc
Task Management
Task Object: In RTOS, The application is decomposed into small, schedulable,
and sequential program units known as “Task”, a basic unit of execution and
is governed by three time-critical properties; release time, deadline and
execution time. Release time refers to the point in time from which the task
can be executed. Deadline is the point in time by which the task must
complete. Execution time denotes the time the task takes to execute.
continuously changing from one state to another. However, only one task is
in the running mode (i.e. given CPU control) at any point of the execution. In
the process where CPU control is change from one task to another, context of
Preemptive Scheduling
Preemptive scheduling allows the interruption of a currently running task, so
another one with more “urgent” status can be run. The interrupted task is
involuntarily moved by the scheduler from running state to ready state. This
dynamic switching between tasks that this algorithm employs is, in fact, a
form of multitasking. It requires assigning a priority level for each task. A
running task can be interrupted if a task with a higher priority enters the
queue.
As an example let’s have three tasks called Task 1, Task 2 and Task 3. Task 1
has the lowest priority and Task 3 has the highest priority. Their arrival times
and execute times are listed in the table below.
Task 1 is the first to start executing, as it is the first one to arrive (at t = 10
μs ). Task 2 arrives at t = 40μs and since it has a higher priority, the
scheduler interrupts the execution of Task 1 and puts Task 2 into running
state. Task 3 which has the highest priority arrives at t = 60 μs. At this
moment Task 2 is interrupted and Task 3 is put into running state. As it is the
highest priority task it runs until it completes at t = 100 μs. Then Task 2
resumes its operation as the current highest priority task. Task 1 is the last to
complete is operation.
Non-preemptive Scheduling: In non-preemptive scheduling, the scheduler has more
restricted control over the tasks. It can only start a task and then it has to
wait for the task to finish or for the task to voluntarily return the control. A
running task can’t be stopped by the scheduler.
Scheduling Algorithms
The most used algorithms in practical RTOS are non-preemptive
scheduling, round-robin scheduling, and preemptive priority scheduling.
Round-Robin Scheduling
Round-robin is a preemptive type of scheduling algorithm. There are no
priorities assigned to the tasks. Each task is put into a running state for a
fixed predefined time. This time is commonly referred to as time-slice. A task
can not run longer than the time-slice. In case a task has not completed by
the end of its dedicated time-slice, it is interrupted, so the next task from the
scheduling queue can be run in the following time slice. A pre-emptied task
has an opportunity to complete its operation once it’s again its turn to use a
time-slice.
Timer: Keeps track of time, crucial for task scheduling and deadlines.
IPC Mechanisms:
Synchronization Techniques:
Many tasks can write messages into the queue, but only one can read
messages from the queue at a time. The reader waits in the message queue
until there is a message to process. Messages can be of any size.
Binary Semaphores:
There are typically two main operations associated with binary semaphores:
Limitations
The key difference between binary and counting semaphores is that binary
semaphores can only take on two values, indicating either that a resource is
available or unavailable, while counting semaphores can take on multiple
values, indicating the number of available resources.
How counting semaphore works?
A counting semaphore allows multiple processes to access a shared resource
simultaneously while ensuring that the maximum number of processes
accessing the resource at any given time does not exceed a predefined limit.
Working Procedure
Mutex
Mutex is a mutual exclusion object that synchronizes access to a resource. It
is created with a unique name at the start of a program. The Mutex is a
locking mechanism that makes sure only one thread can acquire the Mutex
at a time and enter the critical section. This thread only releases the Mutex
when it exits the critical section.
It is a special type of binary semaphore used for controlling access to the
shared resource. It includes a priority inheritance mechanism to avoid
extended priority inversion problems. It allows current higher priority tasks to
be kept in the blocked state for the shortest time possible. However, priority
inheritance does not correct priority inversion but only minimizes its effect.
Define a bit (or flag) that means "A message has been received and is
ready for processing" when it is set to 1, and "there are no messages
waiting to be processed" when it is set to 0.
Define a bit (or flag) that means "The application has queued a
message that is ready to be sent to a network" when it is set to 1, and
"there are no messages queued ready to be sent to the network" when
it is set to 0.
Define a bit (or flag) that means "It is time to send a heartbeat
message onto a network" when it is set to 1, and "it is not yet time to
send another heartbeat message" when it is set to 0.
Event Groups
An event group is a set of event bits. Individual event bits within an event
group are referenced by a bit number. Expanding the example provided
above:
The event bit that means "A message has been received and is ready
for processing" might be bit number 0 within an event group.
The event bit that means "The application has queued a message that
is ready to be sent to a network" might be bit number 1 within the
same event group.
The event bit that means "It is time to send a heartbeat message onto
a network" might be bit number 2 within the same event group.