Es Module 4
Es Module 4
INTRODUCTION
BASICS OF OPERATING SYSTEM
• The operating system acts as a bridge between the user applications/tasks and the
underlying system resources through a set of system functionalities and services.
• The OS manages the system resources and makes them available to the user
applications/tasks on a need basis.
ES & RTOS 8
II. FUNCTIONS OF OS
KERNEL
The kernel is the core of the operating system and is responsible for managing the
system resources and the communication among the hardware and other system
services.
Kernel acts as the abstraction layer between system resources and user applications.
User Applications
Application
Programming
Interface (API)
Memory Management
Kernel services
For a general purpose OS, the kernel contains
Process Management
different services for handling the following.
Time Management
Underlying hardware
ES & RTOS 9
FUNCTIONS OF OS
Process Management
• Process management deals with managing the processes/tasks.
• Process management includes setting up the memory space for the process, loading the
process code into the memory space, allocating system resources, scheduling and managing
the execution of the process, setting up and managing the Process Control Block (PCB), Inter
Process Communication and synchronisation, process termination/deletion, etc.
Primary Memory Management
The Memory Management Unit (MMU) of the kernel is responsible for
• Keeping track of which part of the memory area is currently used by which process
• Allocating and De-allocating memory space on a need basis (Dynamic memory allocation).
File System Management
The file system management service of Kernel is responsible for
• The creation, deletion and alteration of files
• Creation, deletion and alteration of directories
• Saving of files in the secondary storage memory (e.g. Hard disk storage)
• Providing automatic allocation of file space based on the amount of free space available
• Providing a flexible naming convention for the files
ES & RTOS 10
FUNCTIONS OF OS
I/O System (Device) Management
Kernel is responsible for routing the I/O requests coming from different user applications to
the appropriate I/O devices of the system .
The Device Manager is responsible for
• Loading and unloading of device drivers
• Exchanging information and the system specific control signals to and from the device
Secondary Storage Management
The secondary storage management deals with managing the secondary storage memory
devices, if any, connected to the system.
The secondary storage management service of kernel deals with
• Disk storage allocation
• Disk scheduling
• Free Disk space management
ES & RTOS 11
III. TYPES OF OS
Types of Operating System
General Purpose Operating System (GPOS)
The operating systems, which are deployed in general computing systems, are referred as
General Purpose Operating Systems (GPOS).
The kernel of such an OS is more generalised and it contains all kinds of services required
for executing generic applications.
General-purpose operating systems are often quite non-deterministic in behaviour. Their
services can inject random delays into application software and may cause slow
responsiveness of an application at unexpected times.
Personal Computer/ Desktop system is a typical example for a system where GPOSs are
deployed.
Windows XP/MS-DOS etc. are examples for General Purpose Operating Systems.
ES & RTOS 12
III. TYPES OF OS
Real time Operating System (RTOS)
In a broad sense, ‘Real-Time’ implies deterministic timing behaviour.
Deterministic timing behaviour in RTOS context means the OS services consumes only
known and expected amounts of time regardless the number of services.
A Real-Time Operating System or RTOS implements policies and rules concerning time-
critical allocation of a system’s resources.
The RTOS decides which applications should run in which order and how much time needs
to be allocated for each application.
Policies guide the design of an RTOS.
Windows CE, QNX, VxWorks MicroC/OS-II, etc. are examples of Real-Time Operating
Systems (RTOS).
ES & RTOS 13
IV. TASK, PROCESS & THREAD
TASK
• The term ‘task' refers to something that needs to be done.
• Task is also known as ‘Job’ in the operating system context.
PROCESS
• A ‘Process' is a program, or part of it, in execution.
• Process is also known as an instance of a program in execution.
• A process requires various system resources like CPU for executing the process; memory for
storing the code corresponding to the process and associated variables, I/O devices for
information exchange, etc.
Process
• A process mimics a processor in properties and holds
Stack
a set of registers, process status.
Working register
• Program Counter (PC) to point to the next
Status Register
executable instruction of the process
Program Counter
• Stack for holding the local variables associated with
the process and the code corresponding to the
process.
ES & RTOS 15
TASK, PROCESS & THREAD
THREAD
• A thread is a single sequential flow of control within a process.
• Thread is also known as light-weight process.
• Different threads, which are part of a process, share the same address space
• Threads maintain their own thread status (CPU register values), Program Counter
(PC) and stack.
Stack memory for Thread 1
-----------------------------------
Stack memory for Thread 2 Stack memory for
------------------------------------ process
------------------------------------
ES & RTOS 16
V. PROCESS STATES & STATE TRANSITION
Process States & State transition
Created
• The creation of a process to its termination is not a single
step operation.
• The cycle through which a process changes its state from
Incepted into the
memory ‘newly created’ to ‘execution completed' is known as
IO completed or shared ‘Process Life Cycle'.
resource acquired
Ready
Process States
The state at which a process is being created is referred as
‘Created State’.
Blocked preempted Scheduled for
execution
The state, where a process is incepted into the memory and
awaiting the processor time for execution, is known as
‘Ready State'
Waiting for IO or Running
shared resource ‘Running state’ is the state at which the process execution
happens (execution of instructions).
‘Blocked State/Wait State' refers to a state where a running
process is temporarily suspended from execution and does
Completed not have immediate access to resources.
A state where the process completes its execution is known
as ‘Completed State'.
ES & RTOS 17
VI. MULTIPROCESSING & MULTITASKING
Multiprocessing & Multitasking
• In the operating system context multiprocessing describes the ability to execute
multiple processes simultaneously.
• The ability of the operating system to have multiple programs in memory, which are
ready for execution, is referred as multiprogramming.
• In a uniprocessor system, it is not possible to execute multiple processes
simultaneously.
• However, it is possible for a uniprocessor system to achieve some degree of pseudo
parallelism in the execution of multiple processes by switching the execution among
different processes.
• The ability of an operating system to hold multiple processes in memory and switch
the processor (CPU) from executing one process to another process is known as
multitasking. Multitasking creates the illusion of multiple tasks executing in parallel.
Multitasking
ES & RTOS 18
TYPES OF MULTITASKING
Types of Multitasking
1. Co-operative Multitasking
• Co-operative multitasking is the most primitive form of multitasking in which a process gets
a chance to execute only when the currently executing process voluntarily relinquishes the
CPU.
• In this method, any task/process can hold the CPU as much time as it wants
2. Preemptive Multitasking
• Preemptive multitasking ensures that every process gets a chance to execute.
• As the name indicates, in preemptive multitasking, the currently running task/ process is
preempted to give a chance to other tasks/process to execute.
• The preemption of task may be based on time slots or task/process priority.
3. Non-preemptive Multitasking
• In non-preemptive multitasking the process, which is currently given the CPUtime, is
allowed to execute until it terminates or enters the ‘Blocked/Wait’ state.
• In co-operative multitasking, the currently executing process need not relinquish the CPU
when it enters the ‘Blocked/Wait state.
ES & RTOS 19
VII. TASK / PROCESS SCHEDULING
Task / Process Scheduling
• Multitasking involves the execution switching among the different tasks.
• Determining which task/process is to be executed at a given point of time is known as
task/process scheduling.
• Task scheduling forms the basis of multitasking.
Non-preemptive Scheduling
• Non-preemptive scheduling is employed in systems, which implement non-
preemptive multitasking model.
• In this scheduling type, the currently executing task/process is allowed to run until it
terminates or enters the ‘Wait state’ waiting for an I/O or system resource.
ES & RTOS 22
DIFFERENT PROCESS SCHEDULING ALGORITHMS
First Come First Served (FCFS) Scheduling
• First- Come-First-Served (FCFS) scheduling algorithm allocates CPU time to the
processes based on the order in which they enter the ‘Ready’ queue.
• The first entered process is serviced first. It is same as any real world application
where queue systems are used.
• FCFS scheduling is also known as First In First Out (FIFO) where the process which is
put first into the ‘Ready’ queue is serviced first.
Example
Three-processes with process IDs P1, P2, P3 with estimated completion time 10, 5,7 milliseconds respectively, enters the ready
queue together in the order P1, P2, P3. Calculate the waiting time and Turn Around Time (TAT) for each process and the average
waiting time and Turn Around Time (Assuming there is no I/O waiting for the processes).
-------------------------------------------------------------------------------------------------------------------------------------------------------
Average waiting time = (Waiting time for all processes) / No. of Processes = (Waiting time for (P1+P2+P3)) / 3
= (0+10+15)/3 = 25/3 = 8.33 milliseconds
Average Execution Time = (Execution time for all processes)/No. of processes P1 P2 P3
= (Execution time for (Pl+P2+P3))/3 = (10+5+7)/3 = 22/3 = 7.33
Average Turn Around Time = Average waiting time + Average execution time 0 10 15 22
= 8.33 + 7.33 = 15.66 milliseconds Gantt Chart
Or
Average Turn Around Time = (Turn Around Time for all processes) / No. of Processes
= (Turn Around Time for (P1+P2+P3)) / 3 = (10+15+22)/3 =47/3 = RTOS
ES & 15.66 milliseconds 23
DIFFERENT PROCESS SCHEDULING ALGORITHMS
Last Come First Served (LCFS) Scheduling
• The Last-Come-First Served (LCFS) scheduling algorithm also allocates CPU time to
the processes based on the order in which they are entered in the ‘Ready’ queue.
• The last entered process is serviced first.
• LCFS scheduling is also known as Last In First Out (LIFO) where the process, which is
put last into the ‘Ready' queue, is serviced first
ES & RTOS 24
DIFFERENT PROCESS SCHEDULING ALGORITHMS
Shortest Job First (SJF) Scheduling
• Shortest Job First (SJF) scheduling algorithm ‘sorts the ‘Ready’ queue’ each time a
process relinquishes the CPU to pick the process with shortest (least) estimated
completion/run time.
• In SJF, the process with the shortest estimated run time is scheduled first, followed
by the next shortest process, and so on.
Example
Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5,7 milliseconds respectively enters the ready
queue together. Calculate the waiting time and Turn Around Time (TAT) for each process and the Average waiting time and Turn
Around Time (Assuming there is no I/O waiting for the processes) in SJF algorithm.
ES & RTOS 25
DIFFERENT PROCESS SCHEDULING ALGORITHMS
Priority Based Scheduling
• Priority based non-preemptive scheduling algorithm ensures that a process with
high priority is serviced at the earliest compared to other low priority processes in
the ‘Ready’ queue.
• The priority of a task/process can be indicated through various mechanisms.
• The Shortest Job First (SJF) algorithm can be viewed as a priority based scheduling
where each task is prioritised in the order of the time required to complete the task.
The lower the time required for completing a process the highers its priority in SJF
algorithm.
• Another way of priority assigning is associating a priority to the task/process at the
time of creation of the task/process. The priority is a number ranging from 0 to the
maximum priority supported by the OS. Process the task based on the priority.
Example
Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds and priorities 0, 3, 2 {i0—
highest priority, 3—lowest priority) respectively enters the ready queue together. Calculate the waiting time and Turn Around
Time (TAT) for each process and the Average waiting time and Turn Around Time (Assuming there is no I/O waiting for the
processes) in priority based scheduling algorithm. ES & RTOS 26
DIFFERENT PROCESS SCHEDULING ALGORITHMS
Preemptive SJF Scheduling/Shortest Remaining Time (SRT)
Preemptive SJF scheduling algorithm sorts the ‘Ready’ queue when a new process
enters the ‘Ready’ queue and checks whether the execution time of the new
process is shorter than the remaining of the total estimated time for the currently
executing process.
If the execution time of the new process is less, the currently executing process is
preempted and the new process is scheduled for execution.
Preemptive SJF scheduling is also known as Shortest Remaining Time (SRT)
scheduling.
ES & RTOS 27
DIFFERENT PROCESS SCHEDULING ALGORITHMS
Round-robin Scheduling
In Round Robin scheduling, each process in the ‘Ready’ queue is executed for a pre-
defined time slot.
The execution starts with picking up the first process in the ‘Ready’ queue.
It is executed for a pre-defined time and when the pre-defined time elapses or the
process completes the next process in the ‘Ready’ queue is selected for execution.
This is repeated for all the processes in the ‘Ready’ queue.
This reveals that the Round Robin scheduling is similar to the FCFS scheduling and
the only difference is that a time slice based preemption is added to switch the
execution between the processes in the ‘Ready’ queue.
Example
Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds enters the ready queue
together in the order P1, P2, P3. The time slice is 3 milliseconds. Calculate the waiting time and Turn Around Time (TAT) for each
process and the Average waiting time and Turn Around Time (Assuming there is no I/O waiting for the processes) in round-robin
scheduling algorithm.
ES & RTOS 28
IX. INTER PROCESS COMMUNICATION (IPC)
INTER PROCESS COMMUNICATION
The mechanism through which processes/tasks communicate each other is known as Inter
Process/Task Communication (IPC). Inter Process Communication is essential for process
co-ordination.
Shared Memory
• Processes share some area of the memory to communicate among them.
• Information to be communicated by the process is written to the shared memory area.
• Other processes which require this information can read the same from the shared
memory area.
ES & RTOS 29
INTER PROCESS COMMUNICATION (IPC)
The implementation of shared memory concept is kernel dependent. Different
mechanisms are adopted by different kernels for implementing this. A few among them
are:
Pipes
• ‘Pipe’ is a section of the shared memory used by processes for communicating.
• Pipes follow the client-server architecture.
• A process which creates a pipe is known as a pipe server and a process which connects
to a pipe is known as pipe client.
• Pipes are unidirectional
Memory Mapped Objects
• Memory mapped object is a shared memory technique adopted by certain Real-Time
Operating Systems for allocating a shared block of memory which can be accessed by
multiple process simultaneously
Message Queue
• Usually the process which wants to talk to another process posts the message to a First-
In-First-Out (FIFO) queue called ‘Message queue’, which stores the messages
temporarily in a system defined memory object, to pass it to the desired process 30
ES & RTOS
X. DEVICE DRIVER
DEVICE DRIVER
Device driver is a piece of software that acts as a bridge
User applications
between the operating system and the hardware.
Operating System Device drivers are responsible for initiating and managing the
Device Driver
communication with the hardware peripherals.
They are responsible for establishing the connectivity,
Hardware
initializing the hardware and transferring data.
An embedded product may contain different types of hardware
components like Wi-Fi module, File systems, Storage device
interface, etc.
The initialization of these devices and the protocols required
for communicating with these devices may be different. All
these requirements are implemented in drivers and a single
driver will not be able to satisfy all these.
Each class of hardware requires a unique driver component.
ES & RTOS 31
XI. FUNCTIONAL REQUIREMENTS OF RTOS
Functonal Rquirements of RTOS
1.Processor Support
It is not necessary that all RTOS’s support all kinds of processor architecture. It is essential
to ensure the processor support by the RTOS.
2.Memory Requirements
• The OS requires ROM memory for holding the OS files and it is normally stored in a non-
volatile memory like FLASH.
• OS also requires working memory RAM for loading the OS services.
• Since embedded systems are memory constrained, it is essential to evaluate the
minimal ROM and RAM requirements for the OS under consideration.
3. Real-time Capabilities
It is not mandatory that the operating system for all embedded systems need to be Real-
time and all embedded Operating systems-are ‘Real-time' behaviour. Scheduling policies
plays an important role in the ‘Real-time’ behaviour of an OS.
ES & RTOS 32
FUNCTIONAL REQUIREMENTS OF RTOS
4.Kernel and Interrupt Latency
• The kernel of the OS may disable interrupts while executing certain services and it may
lead to interrupt latency.
• For an embedded system whose response requirements are high, this latency should be
minimal.
6.Modularisation Support
• It is very useful if the OS supports modularisation where in which the developer can
choose the essential modules and re-compile the OS image for functioning.
Windows CE is an example for a highly modular operating system.
ES & RTOS 33
FUNCTIONAL REQUIREMENTS OF RTOS
7.Support for Networking and Communication
• The OS kernel may provide stack implementation and driver support for a bunch of
communication interfaces and networking.
• Ensure that the OS under consideration provides support for all the interfaces required
by the embedded product.
ES & RTOS 34
XII. NON-FUNCTIONAL REQUIREMENTS OF RTOS
Non-functonal Rquirements of RTOS
1. Custom Developed or Off the Shelf
• Depending on the OS requirement, it is possible to go for the complete development of
an operating system suiting the embedded system needs or use an off the shelf, readily
available operating system, which is either a commercial product or an Open Source
product, which is in close match with the system requirements.
• Sometimes it may be possible to build the required features-by customising an Open
source OS.
• The decision on which to select is purely de pendent on the development cost, licensing
fees for the OS, development time and availability of skilled resources.
2. Cost
The total cost for developing or buying the OS and maintaining it in terms of commercial
product and custom build needs to be evaluated before taking a decision on the selection
of OS.
ES & RTOS 35
NON-FUNCTIONAL REQUIREMENTS OF RTOS
4. Ease of Use
How easy it is to use a commercial RTOS is another important feature that needs to be
considered in the RTOS selection.
5. After Sales For a commercial embedded RTOS, after sales in the form of e-mail, on-call
services, etc. for bug fixes, critical patch updates and support for production issues, etc.
should be analysed thor¬ oughly.
ES & RTOS 36