Chapter Three
Chapter Three
1 Compiled by Yilu
Module Outline
✓ Real-time OS: definitions, Characteristics, functionality, structure and
support for applications
✓ Features of a RTOS
✓ General and specific microprocessors
✓ Inter process communication
✓ Real time task scheduling
✓ RTOS support for semaphores, queues, and events
✓ Dynamic allocation of tasks
✓ Scheduling: Cyclic scheduling, Priority-based scheduling
✓ Multi-tasking and Concurrency issue
✓ Fault- tolerance
✓ Synchronization techniques: Centralized clock synchronization, Distributed
clock synchronization
Compiled
2 by Yilu
✓ Handling resource sharing and dependencies
Real Time Operating System (RTOS)
➢ RTOS?
1. A RTOS is an OS that guarantees a certain capability within a
specified time constraint.
2. OS is a system program that provides an interface between
application programs and the computer system (hardware).
3. The applications where dependability that a certain task will finish
before a particular deadline is just as obtaining the correct results.
4. Besides meeting deadlines, RTOS must also be able to respond
predictably to unpredictable events and process multiple events
concurrently
Compiled by Yilu 3
Cntd…
➢ Not all embedded systems are designed with an RTOS. Some embedded
4. Safety and security: Safety-critical and security standards are typically the
➢ Though RTOSs may or may not increase the speed of execution, they can
provide much more precise and predictable timing characteristics than
general-purpose OS.
Compiled by Yilu 7
Cntd…
➢ The heart of a real-time OS (and the heart of every OS) is the kernel.
➢ A kernel is the central core of an OS, and it takes care of all the OS jobs:
1. Booting
2. Task Scheduling
3. Standard Function Libraries
➢ In an embedded system, frequently the kernel will boot the system,
initialize the ports and the global data items.
➢ Then, it will start the scheduler and instantiate any hardware timers that
need to be started.
➢ After all that, the Kernel basically gets neglected out of memory, and the
scheduler will start running the child tasks.
Compiled by Yilu 8
Basic Kernel Services
▪ An interrupt handler
▪ Task scheduler
▪ Memory management
Compiled by Yilu 9
Basic functions of RTOS
1. Task Management
➢A task is a unit of execution or unit of work in a software application.
➢ Have timing constraints for tasks
➢ Each task a triplet: (execution time, period, deadline)
➢ Can be initiated any time during
Compiled by Yilu
the period 10
Cntd…
2. Interrupt handling
➢ Unpredictable environment
➢ The Kernel saves the state of the interrupted task and then
determines which task it should run next.
➢ The Kernel restores the state of the task and passes control of
the CPU for that task.
Compiled by Yilu 13
General and specific microprocessors
Compiled by Yilu 17
Cntd…
❑ What happened during switching ?
Compiled by Yilu 18
Inter-process communication
➢ Tasks usually need to communicate and synchronize with each other for
➢ RTOS provides inbuilt inter-task primitives , which are kernel objects that
❖ Semaphores
❖ Message queues
❖ Signal and so on
Compiled by Yilu 19
Cntd…
❑ Semaphores is a kernel object that one or more tasks can acquire or release for :
Mutual exclusion
Signaling the occurrence of an event
Synchronizing activities among tasks
➢ Semaphores have
➢ An associated semaphore control block (SCB),
➢ A unique ID,
➢ A user-assigned value (binary or a count), and
➢ A task-waiting list.
➢ There are two types
Binary semaphores (0 or 1)
If value =0 => semaphore is not available
If value = 1 => semaphore available
Counting semaphores (>= 0)
Compiled by Yilu 20
uses a count to allow it to be acquired or released multiple times.
Real time task scheduling
❑ The two major groups are run-time and pre-run-time schedulers.
A. Run time Scheduler is referred to priority based schedulers where the decision
of which task will execute next is computed dynamically at run time.
B. Pre-run-time schedulers are those which computation work about the execution
line is done previous to run-time.
▪ These are also known as cyclic or clock driven schedulers.
A. Priority-based Scheduling is based in the idea that each task in the systems is
assigned a priority according to some decision base.
➢ Consistent with priority, the task will be assigned for execution while the system
is running.
➢ The main question here is, which factor do we use to assign the priorities?
❖ priority-based algorithms, dynamic-priority and static-priority scheduling.
Compiled by Yilu 21
Cntd…
B. Cyclic scheduling (also known as clock-driven, pre-run time)
➢ This schedule is computed off-line before the system begins to execute, and the
computation is based on the knowledge of the release times and resource
requirements of all the jobs for all times.
➢ It offers, general advantages for deterministic systems, in which release times and
job demands don’t vary or vary slightly with time.
➢ But the problem is what happens with those systems in which the future work
load is relatively unpredictable?
❑ Scheduling policies: keeping record of the state of each task and allocates the
CPU to one of them
➢ Scheduler is responsible for time-sharing of CPU among tasks.
Compiled by Yilu 22
Cntd…
➢ a buffer-like object through which tasks send and receive messages to communicate
Compiled by Yilu 27
Multi-tasking and Concurrency issue
Compiled by Yilu 29
Fault tolerance
Compiled by Yilu 30
Synchronization techniques: Centralized clock synchronization, Distributed clock
synchronization
Compiled by Yilu 33
Handling resource sharing and dependencies: Priorities and reentrancy, Resource
sharing protocols
➢ Most the different task scheduling algorithms that the different tasks in a
➢ A common form of dependency arises when one task needs the results of
Compiled by Yilu 37