RTOS - Module 3
RTOS - Module 3
TIME OPERATING
SYSTEMS
MODULE - 3, Part 2
MODULE 3
• Real Time Operating Systems:
Structure and characteristics of Real
Time Systems
Applications: Controlling
Applications: Office , Data
aircraft or nuclear reactor ,
4 centers , System for home
scientific research
etc
equipments
• https://robocraze.com/blogs/post/architecture-of-rtos-part-1
• https://electricalfundablog.com/rtos-real-time-operating-system/
Characteristics of Real-time
System:
Time Constraints: Time constraints related with real-time systems
simply means that time interval allotted for the response of the ongoing
program. This deadline means that the task should be completed within
this time interval.
• Reliability
• Predictability
• Performance
• Compactness
• Scalability.
Key Characteristics of an RTOS
• Reliability: Embedded systems must be reliable.
Depending on the application, the system might need to
operate for long periods without human intervention.
• Predictability: The term deterministic describes RTOSes
with predictable behaviour, in which the completion of
operating system calls occurs within known timeframes.
• Performance: An embedded system must perform fast
enough to fulfill its timing requirements.
Key Characteristics of an RTOS
• Compactness: Application design constraints and cost
constraints help determine how compact an embedded
system can be. For example, a cell phone clearly must be
small, portable, and low cost.
● Task─ term used for the process in the RTOSes for the
embedded systems.
● For example, VxWorks and COS-II are the RTOSes, which
use the term task.
• Each task has
• Task Control Block (TCB)
• Unique ID and Common memory
• States (idle, ready, running, blocked, finished)
Task Control Block (TCB)
A task, its associated parameters, and
supporting data structures.
Task
Examples of system tasks include:
• Initialization or startup task: initializes the system and
creates and starts system tasks
• Idle task :uses up processor idle cycles when no other
activity is present.
• Logging task: logs system messages
In each of these cases, the task is moved from the running state
to the blocked state
Blocked State
• The possibility of blocked states is extremely important
in real-time systems because without blocked states,
lower priority tasks could not run. If higher priority tasks
are not designed to block, CPU starvation can result.
Blocking conditions are met include the following:
•a semaphore token for which a task is waiting is released,
•a message, on which the task is waiting, arrives in a
message queue,
•a time delay imposed on the task expires.
• When a task becomes unblocked, the task might move
from the blocked state to the ready state if it is not the
highest priority task.
• If the unblocked task is the highest priority task, the task
moves directly to the running state.
Task Creation and Deletion
• The task is first created and put into a suspended state; then, the
task is moved to the ready state when it is started.
• During the deletion process, a kernel terminates the task and frees
memory by deleting the tasks TCB and stack.
However, when tasks execute, they can acquire memory or access
resources using other kernel objects. If the task is deleted incorrectly,
the task might not get to release these resources. For example, assume
that a task acquires a semaphore token to get exclusive access to a
shared data structure. While the task is operating on this data
structure, the task gets deleted. If not handled appropriately, this
abrupt deletion of the operating task can result in:
• a corrupt data structure, due to an incomplete write operation,
• an unreleased semaphore, which will not be available for other tasks
that might need to acquire it, and
• an inaccessible data structure, due to the unreleased semaphore.
As a result, premature deletion of a task can result in memory or
Task Scheduling
Obtaining Task Information
Semaphore
A semaphore (sometimes called a semaphore
token ) is a kernel object that one or more threads of
execution can acquire or release for the purposes of
synchronization or mutual exclusion.
• Binary,
• Counting, and
• Mutual-exclusion (Mutex) Semaphores.
Binary Semaphores
• A binary semaphore can have a value of either 0 or 1.
• When a binary semaphore’s value is 0, the semaphore
is considered unavailable (or empty);
• when the value is 1, the binary semaphore is
considered available (or full ).
Counting Semaphores
• A counting semaphore uses a count to allow it to be
acquired or released multiple times.
• Note that some kernels might use the terms lock and
unlock for a mutex instead of acquire and release .
Mutual Exclusion (Mutex)
Semaphores
Mutual Exclusion (Mutex)
Semaphores
• Depending on the implementation, a mutex can
support additional features not found in binary or
counting semaphores.
Memory
sharing
Message Queues
• A message queue is a buffer-like object through which
tasks and ISRs send and receive messages to
communicate and synchronize with data.
• A message queue is like a pipeline.
• It temporarily holds messages from a sender until the
intended receiver is ready to read them.
• This temporary buffering decouples a sending and
receiving task; that is, it frees the tasks from having to
send and receive messages simultaneously.
• EG:
• a temperature value from a sensor,
• a text message to print to an LCD,
• a keyboard event.
• Primary intertask communication mechanism within a
single CPU.
• Allow a variable number of messages (varying in
length) to be queued in first-in-first-out (FIFO) order.
• Any task or ISR can send messages to the message
queue
• Any task can receive messages from the message queue
• Multiple tasks can send to and receive from the same
message queue
A message queue, its associated parameters,
and supporting data structures.
• It is the kernel s job to assign a unique ID to a message queue and to
create its QCB and task-waiting list. The kernel also takes developer-
supplied parameters such as the length of the queue and the
maximum message length to determine how much memory is
required for the message queue.
• After the kernel has this information, it allocates memory for the
message queue from either a pool of system memory or some
private memory space.
• The message queue itself consists of a number of elements, each of
which can hold a single message. The elements holding the first and
last messages are called the head and tail respectively. Some
elements of the queue may be empty (not containing a message). The
total number of elements (empty or not) in the queue is the total
length of the queue . The developer specified the queue length when
The state diagram for a message queue.
• As with other kernel objects, message queues follow the
logic of a simple FSM, as shown in Figure. When a message
queue is first created, the FSM is in the empty state.
• If a task attempts to receive messages from this message
queue while the queue is empty, the task blocks and, if it
chooses to, is held on the message queue’s task-waiting list,
in either a FIFO or priority-based order.
Typical Message Queue Operations
Typical message queue operations include the following:
• creating and deleting message queues,
• sending and receiving messages, and
• obtaining message queue information.
Creating and Deleting Message Queues
Sending and Receiving Messages
Obtaining Message Queue Information
Typical Message Queue Use
• non-interlocked, one-way data communication,
• interlocked, one-way data communication,
• interlocked, two-way data communication, and
• broadcast communication
Non-Interlocked, One-Way Data Communication
}
Interlocked, One-Way Data Communication
● A pipe provides a simple data flow facility so that the reader becomes
blocked when the pipe is empty, and the writer becomes blocked when
the pipe is full.
● Typically, a pipe is used to exchange data between a data-producing
task and a data-consuming task.
• A pipe is conceptually similar to a message queue but with
significant differences.
• For example,
○ unlike a message queue, a pipe does not store multiple
messages. Instead, the data that it stores is not structured,
but consists of a stream of bytes.
○ Also, the data in a pipe cannot be prioritized; the data flow
is strictly first-in, first-out FIFO.
○ Finally, as is described below, pipes support the powerful
select operation, and message queues do not.
Pipe Control Blocks
● Pipes can be dynamically created or destroyed.
● The kernel creates and maintains pipe-specific information in an
internal data structure called a pipe control block .
● A pipe control block contains a kernel-allocated data buffer for the
pipe’s input and output operation. The size of this buffer is
maintained in the control block and is fixed when the pipe is created;
it cannot be altered at run time.
● The current data byte count, along with the current input and output
position indicators, are part of the pipe control block.
○ The current data byte count indicates the amount of readable data
in the pipe.
○ The input position specifies where the next write operation begins
in the buffer.
○ Similarly, the output position specifies where the next read
Pipe Control Blocks
Examples: