0% found this document useful (0 votes)
24 views

ES Module-3

The document discusses several topics related to real-time operating systems (RTOS): 1) It defines processes and threads, and explains the different states a process can be in. It also describes four thread binding models. 2) It provides examples of hard and soft real-time systems, listing RTOS examples like QNX and VxWorks. 3) It discusses how to choose an RTOS, noting important factors like performance, features, and vendor support should be considered.

Uploaded by

Kusuma Namana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

ES Module-3

The document discusses several topics related to real-time operating systems (RTOS): 1) It defines processes and threads, and explains the different states a process can be in. It also describes four thread binding models. 2) It provides examples of hard and soft real-time systems, listing RTOS examples like QNX and VxWorks. 3) It discusses how to choose an RTOS, noting important factors like performance, features, and vendor support should be considered.

Uploaded by

Kusuma Namana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ES MODULE-3

RTOS FUNDAMENTALS AND PROGRAMMING

PART-A

1. Define process and explain the process states and state


transitions with a neat diagram.

The program under execution is called Process. Process is an


active entity. Process goes through different states throughout the
life cycle during the process execution, which is known as process
states. All the information associated with the process is stored in
the Process Control Block (PCB).

List of States of the Process


New State
This is the first state of the process life cycle. When process
creation is taking place, the process is in a new state.

Ready State
When the process creation gets completed, the process comes
into a ready state. During this state, the process is loaded into the
main memory and will be placed in the queue of processes which
are waiting for the CPU allocation.

Running State
Whenever the CPU is allocated to the process from the ready
queue, the process state changes to Running.

Block or Wait State


When the process is executing the instructions, the process might
require carrying out a few tasks which might not require CPU. If
the process requires performing Input-Output tasks or the process
needs some resources which are already acquired by other
processes, during such conditions the process is brought back into
the main memory, and the state is changed to Blocking or Wait for
the state. Process is placed in the queue of processes that are in
waiting or block state in the main memory.

Terminated or Completed
When the entire set of instructions is executed and the process is
completed. The process is changed to terminated or completed
state. During this state the PCB of the process is also deleted.

2. Explain the different thread binding models for user and kernel
level threads.

Thread Models in Operating System


A thread is a light weight process which is similar to a process
where every process can have one or more threads. Each thread
contains a Stack and a Thread Control Block.
There are four basic thread models:
1. User Level Single Thread Model :

● Each process contains a single thread.


● Single process is itself a single thread.
● The process table contains an entry for every process by
maintaining its PCB.

2. User Level Multi Thread Model :

● Each process contains multiple threads.


● All threads of the process are scheduled by a thread library at
user level.
● Thread switching can be done faster than process switching.
● Thread switching is independent of the operating system
which can be done within a process.
3. Kernel Level Single Thread Model :
● Each process contains a single thread.
● Thread used here is kernel level thread.
● Process table works as a thread table.

4. Kernel Level Multi Thread Model :

● Thread scheduling is done at kernel level.


● Fine grain scheduling is done on a thread basis.
● If a thread is blocked, another thread can be scheduled
without blocking the whole process.
● Thread scheduling at Kernel process is slower compared to
user level thread scheduling.
● Thread switching involves switching.

3. Write the basic design principles when using an RTOS to design


a sample RTOS.
4. What is the difference between Hard and Soft real time systems?
Give an example for Hard and Soft real time kernels?

5. Explain how threads and processes are related? What are the
common processes and threads?

Process:
Refer PART-A Q.1

There are various Process States, they are:


● NEW: A new process is being created.
● READY: A process is ready and waiting to be allocated to a
processor.
● RUNNING: The program is being executed.
● WAITING: Waiting for some event to happen or occur.
● TERMINATED: Execution finished.

Thread

A thread is the subset of a process and is also known as the


lightweight process. A process can have more than one thread, and
these threads are managed independently by the scheduler. All the
threads within one process are interrelated to each other. Threads
have some common information, such as data segment, code
segment, files, etc., that is shared to their peer threads. But
contains its own registers, stack, and counter.
PART-B

1. Explain in detail about the real time operating systems with an


example.
A real-time operating system (RTOS) is a special-purpose
operating system used in computers that has strict time
constraints for any job to be performed. It is employed mostly in
those systems in which the results of the computations are used to
influence a process while it is executing. Whenever an event
external to the computer occurs, it is communicated to the
computer with the help of some sensor used to monitor the event.
The sensor produces the signal that is interpreted by the operating
system as an interrupt. On receiving an interrupt, the operating
system invokes a specific process or a set of processes to serve the
interrupt.

The various examples of Real-time operating systems are:

● MTS
● Lynx
● QNX
● VxWorks etc.

Hard Real-Time operating system:


These operating systems guarantee that critical tasks are
completed within a range of time.

For example, a robot is hired to weld a car body. If the robot welds
too early or too late, the car cannot be sold, so it is a hard
real-time system that requires complete car welding by robot
hardly on the time.

Soft real-time operating system:


This operating system provides some relaxation in the time limit.
For example – Multimedia systems, digital audio systems etc.

Firm Real-time Operating System:


RTOS of this type have to follow deadlines as well. In spite of its
small impact, missing a deadline can have unintended
consequences, including a reduction in the quality of the product.
Example: Multimedia applications.

2. Discuss in detail how processes and threads are used in


embedded systems.

Processes and Threads

A process is an instance of program execution. This means, for


example, that if you open up two browser windows then you have
two processes, even though they are running the same program.

The life-cycle of a process can be described by a state diagram


which has states representing the execution status of the process
at various times and transitions that represent changes in
execution status.
The operating system maintains management information about a
process in a process control block (PCB). Modern operating
systems allow a process to be divided into multiple threads of
execution, which share all process management information
except for information directly related to execution. This
information is held in a thread control block (TCB).

Threads in a process can execute different parts of the program


code at the same time. They can also execute the same parts of the
code at the same time, but with different execution state:

● They have independent current instructions; that is, they


have (or appear to have) independent program counters.
● They are working with different data; that is, they are (or
appear to be) working with independent registers.
This is accomplished by moving execution state out of the PCB into
thread control blocks (TCBs). Each thread has its own TCB.

Processes start out with a single main thread. The main thread can
create new threads using a thread fork system call. The new
threads can also use this system call to create more threads.
Consequently, a thread not only belongs to a process; it also has a
parent thread - the thread that created it.

3. Define Semaphores? Explain in detail about types of


Semaphores.

Semaphores are integer variables that are used to solve the critical
section problem by using two atomic operations, wait and signal
that are used for process synchronization.

The definitions of wait and signal are as follows −


● Wait
The wait operation decrements the value of its argument S, if
it is positive. If S is negative or zero, then no operation is
performed.

● Signal The signal operation increments the value of its


argument S.

Types of Semaphores

There are two main types of semaphores i.e. counting semaphores


and binary semaphores. Details about these are given as follows −

● Counting Semaphores
These are integer value semaphores and have an unrestricted
value domain. These semaphores are used to coordinate the
resource access, where the semaphore count is the number
of available resources. If the resources are added, semaphore
count automatically increments and if the resources are
removed, the count is decremented.
● Binary Semaphores
The binary semaphores are like counting semaphores but
their value is restricted to 0 and 1. The wait operation only
works when the semaphore is 1 and the signal operation
succeeds when semaphore is 0. It is sometimes easier to
implement binary semaphores than counting semaphores.

4. Discuss in detail about how to choose an RTOS with an example.


We consider a few characteristics when it comes to choosing a
RTOS:

Performance

RTOS performance is a critical factor to consider when selecting


an RTOS.

First, memory requirements such as ROM, flash and RAM


footprints need to be considered. RTOSes are powerful and with
that power comes additional code and data needs. Second,
processing speed such as interrupt latency and context switch
times should be reviewed. A high quality RTOS will document
these parameters for a variety of architectures and clock speeds.

Features

Every RTOS doesn’t have the exact same features or the features
implemented in the most optimal manner. Developers need to
evaluate which features are the most critical to the system's
success and select an RTOS that has those features. Developers
may want to consider scalability, safety certifications or even the
efficiency of memory protection schemes

An RTOS that can statically allocate tasks might be the better


choice.

Cost

Undoubtedly one of the largest, if not only thought about RTOS


characteristics is cost.A few considerations for commercial
RTOSes are the upfront costs for licensing and any recurring
licenses such as royalties. In additional to these obvious costs,
developers need to also consider the total cost of ownership for
the RTOS. That is, the cost to learn, setup, integrate and debug the
selected operating system

Ecosystem

Having the best performance, features and cost doesn’t mean a


thing if there isn’t a large and vibrant community to support the
RTOS. A software products ecosystem is a critical piece of the
selection process in order to ensure ease of integration, support
and product lifetime.

Middleware

Many RTOSes come with middleware components or have third


parties who have developed components that integrate into the
RTOS. Developers should evaluate their RTOSes middleware and
determine what the integration effort might be. Sometimes the
integration is seamless while other times it is an obvious
nightmare.

Verify that the middleware has common components such as USB,


TCP/IP, file systems and graphics generators

5. Define task scheduling? Discuss in detail about the task states


and scheduling?

The process of deciding which task will utilize the cpu time is
called task scheduling. The scheduling of the task may be on the
basis of their priorities. The priority assignment mechanism for the
tasks can be either static or dynamic. In the case of static priority
assignment the priority of task is assigned as soon as the task is
created, thereafter the priorities cannot be changed. In dynamic
assigning the priorities of the task can be changed during the
runtime.

Task States

At any one moment in time, just one task is actually running. Aside
from CPU time spent running interrupt service routines (more on
that in the next article) or the scheduler, the “current” task is the
one whose code is currently being executed and whose data is
characterized by the current register values. There may be other
tasks that are “ready” (to run) and these will be considered when
the scheduler is executed.

Scheduling :

The way that time is allocated between tasks is termed


“scheduling”. The scheduler is the software that determines which
task should be run next. The logic of the scheduler and the
mechanism that determines when it should be run is the
scheduling algorithm.

Run to Completion (RTC) Scheduler

RTC scheduling is very simplistic and uses minimal resources. It is,


therefore, an ideal choice, if the application’s needs are fulfilled.

Round Robin (RR) Scheduler

An RR scheduler is similar to RTC, but more flexible and, hence,


more complex. However, with the RR scheduler, the task does not
need to execute a return in the top level function. It can relinquish
the CPU at any time by making a call to the RTOS.

Time Slice (TS) Scheduler

A TS scheduler is the next step in complexity from RR. Time is


divided into “slots”, with each task being allowed to execute for the
duration of its slot

Priority Scheduler

Most RTOSes support Priority scheduling. The idea is simple: each


task is allocated a priority and, at any particular time, whichever
task has the highest priority and is “ready” is allocated the CPU.
6. Explain in detail about the semaphores with an example.

Refer Part-B Q.3

7. Explain the basic functions of a real-time kernel in detail?

A real-time kernel is software that manages the time of a


microprocessor to ensure that time-critical events are processed
as efficiently as possible. The use of a kernel simplifies the design
of embedded systems because it allows the system to be divided
into multiple independent elements called tasks.

A real-time kernel is not necessarily superior or better than a


standard kernel. Instead, it meets different business or system
requirements. It is an optimized kernel designed to maintain low
latency, consistent response time, and determinism. By way of
comparison, a standard RHEL kernel focuses on
throughput-oriented operations and fair scheduling of tasks. The
real-time kernel is also known as kernel-rt or preempt-rt.

The simplest way to identify a real-time kernel is to execute the


uname -r command on the terminal, and then look for the rt
keyword in the kernel version. If rt is missing, then the system uses
the standard kernel.

The following output is an example:


#uname -r

3.10.0-1127.10.1.rt56.1106.el7

Some important kernel-rt mechanisms include:


● A task's priority is checked (1-99) under heavy load.
● High priority (99) tasks are given preference for CPU
execution.
● Does not use the Completely Fair Scheduling (CFS) policy.

8. Explain multi-processing, multitasking and multiprogramming


in a real time operating system.

Multiprocessing in RTOS

An SMP (Symmetric Multiprocessing) system, by definition, has


imultiple identical processors connected to a set of peripherals,
such as memory and I/O devices, on a common high-speed bus.
The term symmetric is used because each processor has the same
access mechanism to the shared memory and peripheral devices.

Advantages

● Two processing units running in parallel complete a set of


tasks more quickly than one processor. Four processors are,
likewise, better than two.
● An SMP system that can be scaled by adding more processing
cores and/or peripheral devices to execute more tasks in
parallel offers a viable platform for scalability.
● If one processor suffers a fatal failure, another can take over
its work seamlessly, reducing downtime.

Multitasking in RTOS:

Real-time operating systems (RTOS) are built around a


multitasking kernel that controls the allocation of time slices to
tasks. A time slice is the period of time a given task has for
execution before it is stopped and replaced by another task. This
process, also known as context switching, repeats continuously.
When context switching occurs, the executing task is stopped, the
processor registers are saved in memory, the processor registers
of the next available task are loaded into the CPU, and the new task
begins execution.

Multiprogramming in RTOS

Real-Time Multiprogramming Operating System (RTMOS) was a


24-bit process control operating system developed in the 1960s by
General Electric that supported both real-time computing and
multiprogramming. Programming was done in assembly language
or Process FORTRAN. The two languages could be used in the
same program, allowing programmers to alternate between the
two as desired.

Multiprogramming operating systems are now considered


obsolete, having been replaced by multitasking.

9. Discuss in detail about shared memory with an example.

Shared memory is a memory shared between two or more


processes. Each process has its own address space; if any process
wants to communicate with some information from its own
address space to other processes, then it is only possible with IPC
(inter-process communication) techniques.

Shared memory is the fastest inter-process communication


mechanism. The operating system maps a memory segment in the
address space of several processes to read and write in that
memory segment without calling operating system functions.
For applications that exchange large amounts of data, shared
memory is far superior to message passing techniques like
message queues, which require system calls for every data
exchange. To use shared memory, we have to perform two basic
steps:

● Request a memory segment that can be shared between


processes to the operating system.
● Associate a part of that memory or the whole memory with
the address space of the calling process.

A shared memory segment is a portion of physical memory that is


shared by multiple processes. In this region, processes can set up
structures, and others may read/write on them. When a shared
memory region is established in two or more processes, there is no
guarantee that the regions will be placed at the same base address.
Semaphores can be used when synchronization is required.

10. What is a device driver? Explain the role of device drivers in


an embedded operating system.

Device Driver in computing refers to a special kind of software


program or a specific type of software application that controls a
specific hardware device that enables different hardware devices
to communicate with the computer’s Operating System. A device
driver communicates with the computer hardware by computer
subsystem or computer bus connected to the hardware.

ROLE:

Device Drivers are essential for a computer system to work


properly because without a device driver the particular hardware
fails to work accordingly, which means it fails in doing the
function/action it was created to do. Most use the term Driver, but
some may say Hardware Driver, which also refers to the Device
Driver.

Types of Device Driver:

For almost every device associated with the computer system


there exists a Device Driver for the particular hardware. But it can
be broadly classified into two types i.e.,

1. Kernel-mode Device Driver –


This Kernel-mode device driver includes some generic
hardware that loads with the operating system as part of the
OS; these are BIOS, motherboard, processor, and some other
hardware that are part of kernel software. These include the
minimum system requirement device drivers for each
operating system.
2. User-mode Device Driver –
Other than the devices which are brought by the kernel for
working the system the user also brings some devices for use
during the using of a system that devices need device drivers
to function those drivers fall under User mode device driver.
For example, the user needs any plug-and-play action that
comes under this.

You might also like