Rtos and Ide For Embedded System Design: Roopesh Kumar B N, Assistant Professor, Cse, Ksit
Rtos and Ide For Embedded System Design: Roopesh Kumar B N, Assistant Professor, Cse, Ksit
Rtos and Ide For Embedded System Design: Roopesh Kumar B N, Assistant Professor, Cse, Ksit
What are the functions handled by the general purpose kernel? Explain.
Process Management
Primary Memory Management
I/O System(Device) Management
File System Management
Secondary Storage Management
3
ROOPESH KUMAR B N,CSE,KSIT
Process Management
Managing the process/tasks
Setup the memory space for process
Load program/code into space(memory)
Scheduling & managing the execution of the process
Setting up & managing the PCB
Inter process communication & system synchronization process termination
& deletion
Primary Memory Management
The MMU of kernel - Keeping track of which part of memory area is
correctly used by which process.
Allocating & de allocating the memory spaces .
I/O System(Device) Management
Kernel is responsible for routing the I/O request coming from different user
applications .
Device manager of the kernel is responsible for handling I/O device related
operations.
Exchanging the information.
4
ROOPESH KUMAR B N,CSE,KSIT
File System Management
The file system management service of kernel is responsible for
The creation & deletion of files.
Creation and deletion and alterations of directories.
Saving the file on secondary storage.
Providing automatic allocation of spaces.
Providing a flexible naming convention for the files.
Secondary Storage Management
Disk storage allocation
Disk scheduling
Free disk space management
In addition kernel also ensures various protection policies for protecting the
system.
Provides interrupt handler mechanisms for all external /internal interrupt
generated by the system.
5
ROOPESH KUMAR B N,CSE,KSIT
What are Kernel space and user space?
Memory space at which the kernel code is located is known as kernel space.
Memory space at which user applications are located known as user space.
What is Swapping?
The act of loading code into and out of the Main memory.
Swapping happens between main memory and Secondary Storage memory.
What are Monolithic kernel and Microkernel?
Monolithic kernel
In monolithic kernel architecture, all kernel services run in kernel space.
Disadvantage of this design is that any failure or error leads to the crashing of
the entire kernel application,
Examples are LINUX,SOLARIS,MS-DOS kernels.
Microkernel
In Microkernel design, only essential applications run in kernel space other
operating system services run in user space as programs called as servers.
Examples are mininx3 and qnx.
Benefits of Microkernel based design
Robustness
Configurability
6
ROOPESH KUMAR B N,CSE,KSIT
7
ROOPESH KUMAR B N,CSE,KSIT
Types of an operating systems
Distinguish between GPOS and RTOS?
General Purpose Operating System[GPOS]
A GPOS is used for systems/applications that are not time critical.
The OS which are deployed in general computing systems are referred as
general purpose OS.[Desktop, Laptop, Tablet computers].
The kernel of such OS is more generalized & it contains all kinds of services
required for executing generic applications
GPOS are non-deterministic in behavior and Response Times not Guaranteed
Examples: Windows, Linux, Unix etc.
Real Time Operating System[RTOS]
An RTOS is used for time critical systems. RTOS is an OS intended to serve
real-time application requests.[Embedded Computing].
Real-time implies deterministic timing behavior and Response Time is
Guaranteed
RTOS decides which application should run in which order & how much
time needs to be allocated for each applications.
Examples: WindowsCE,UNIX,VxWorks,Micros/OS-II 8
ROOPESH KUMAR B N,CSE,KSIT
Real time kernel?
Kernel of the real time operating system is referred to as real time kernel.
Compared to conventional OS Kernel, It is highly Specialized and contain
minimal set of services
The Basic functions of Real time kernel are listed below
A real-time kernel is software that manages the time of microprocessor to
ensure that time-critical events are processed as efficiently as possible.
TCB?
A task control block (TCB) is a data structure used by kernels to maintain information
about a task.
Each task requires its own TCB
Task Control Block is used for holding the information corresponding to a task.
Task ID
Task State
Task Type
Task Priority
Task Context Pointer
Task Memory Pointer
Task System Resource Pointers
Task Pointers
Other Parameters
Task/Process Scheduling?
CPU is shared among various tasks/process.
The task scheduling is the activity of assigning the tasks in the system in a
manner, that will optimize the overall performance of the application, while
assuring the correctness of the result.
A kernel applications called scheduler, handles the task scheduling.
Task/Process Synchronization?
Deals with concurrent accessing of system a resource.
Error/Exception Handling?
Ex: Insufficient memory, time outs, dead locks, dead line missing, bus error,
divide by zero, unknown instruction execution.
11
ROOPESH KUMAR B N,CSE,KSIT
Memory Management?
RTOS makes use of ‘Block Based Memory’ allocation techniques instead of
the usual dynamic memory allocation technique used by GPOS.
RTOS kernel uses blocks of fixed size dynamic memory.
Block is allocated for a task on a need of basis.
A few RTOS kernel implements Virtual Memory concepts.
Block memory avoid the garbage collection overhead.
Interrupt Handler?
Interrupts can be either Synchronous Asynchronous. Interrupts which occurs in
synch with the currently executing task is known as synchronous interrupts.
Asynchronous interrupts are those which occurs at any point of execution of
any task & are not in sync with currently executing tasks.
Most of the real time kernel implements nested interrupts.
Time management?
Implemented with RTC(real time clock)
Handles timer tick interrupt
Hard real time?
Soft real time?
12
ROOPESH KUMAR B N,CSE,KSIT
Describe the difference between the soft real-time systems and hard real-
time systems with examples?
Hard real time systems?
Real time operating systems that strictly adhere to the timing constraint for a
task is referred to as Hard real time systems.
They are time critical, missing any deadline may produce catastrophic
results.
“A late answer is a wrong answer”
Example: ABS ,Air Traffic Control System
13
ROOPESH KUMAR B N,CSE,KSIT
Hard real time systems(Example Description)
Air traffic controllers monitor the location of aircraft in their assigned airspace
by radar and communicate with the pilots by radio. To prevent collisions
Air traffic control keeps aircraft from colliding with each other.
Any delay in response causes a severe damage.
In general, Suitable for applications that are time critical and where the response
time is so important (Embedded systems where missing deadlines are not
acceptable).
14
ROOPESH KUMAR B N,CSE,KSIT
What are Tasks, Processes & Threads ?
In the Operating System context, a task is defined as the program in execution
Task is also known as ‘Job’ in the operating system context.
A program or part of it in execution is called as ‘Process’.
The terms ‘Task’, ‘job’ and ‘Process’ refer to the same entity in the Operating
System context and most often they are used interchangeably.
A thread is a path of execution within a process. A process can contain
multiple threads.
Context switching is inexpensive and fast Context switching is complex and involves
lot of OS overhead and is comparatively
slower.
If a thread expires, its stack is reclaimed If a process dies, the resources allocated to
by the process. it are reclaimed by the OS and all the
associated threads of the process also dies.
19
ROOPESH KUMAR B N,CSE,KSIT
Define the following terms?
Multiprocessing: The ability to execute multiple processes simultaneously is referred
as multiprocessing.
Multiprocessor systems: Systems which are capable of performing multiprocessing
are known as multiprocessor systems.
Multiprogramming: The ability of the Operating System to have multiple programs
in memory, which are ready for execution, is referred as multiprogramming.
Multitasking: Multitasking refers to the ability of an operating system to hold
multiple processes in memory and switch the processor (CPU) from executing one
process to another process.
Multitasking involves ‘Context switching’, ‘Context saving’ and ‘Context retrieval’
Context switching: Context switching refers to the switching of execution context
from task to other task.
Context saving: When a task/process switching happens, the current context of
execution should be saved to (Context saving) retrieve it at a later point of time when
the CPU executes the process, which is interrupted currently due to execution
switching.
Context retrieval: During context switching, the context of the task to be executed is
retrieved from the saved context list. This is known as Context retrieval
20
ROOPESH KUMAR B N,CSE,KSIT
Explain the different types of Multitasking?
Co-operative Multitasking :Co-operative multitasking is the most primitive form
of multitasking in which a task/process gets a chance to execute only when the
currently executing task/process voluntarily relinquishes the CPU. In this
method, any task/process can avail the CPU as much time as it wants. Since this
type of implementation involves the mercy of the tasks each other for getting the
CPU time for execution, it is known as co-operative multitasking.
21
ROOPESH KUMAR B N,CSE,KSIT
Explain the various factors on which scheduling algorithms are selected?
CPU Utilization: The scheduling algorithm should always make the CPU
utilization high. CPU utilization is a direct measure of how much percentage of
the CPU is being utilized.
Throughput: This gives an indication of the number of processes executed per
unit of time. The throughput for a good scheduler should always be higher.
Turnaround Time: It is the amount of time taken by a process for completing its
execution. It includes the time spent by the process for waiting for the main
memory, time spent in the ready queue, time spent on completing the I/O
operations, and the time spent in execution. The turnaround time should be a
minimum for a good scheduling algorithm.
Waiting Time: It is the amount of time spent by a process in the ‘Ready’ queue
waiting to get the CPU time for execution. The waiting time should be minimal
for a good scheduling algorithm.
Response Time: It is the time elapsed between the submission of a process and
the first response. For a good scheduling algorithm, the response time should be
as least as possible.
22
ROOPESH KUMAR B N,CSE,KSIT
Non preemptive Scheduling Examples
In Non-preemptive scheduling, the CPU is allocated to the processes till it
terminates or switches to waiting state.
First Come First Served (FCFS)/First In First Out (FIFO) Scheduling
Last Come First Served (LCFS)/Last In First Out (LIFO) Scheduling
Shortest Job First (SJF) Scheduling
Priority based Scheduling
NOTE: Students must explain the above scheduling techniques and solve
one or two problems with respect to all scheduling algorithms mentioned
above.
23
ROOPESH KUMAR B N,CSE,KSIT
Non preemptive Scheduling Examples
First Come First Served (FCFS)/First In First Out (FIFO) Scheduling
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
Turn Around Time (TAT) for P1 = 10 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P2 = 15 ms (-Do-)
Turn Around Time (TAT) for P3 = 22 ms (-Do-)
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
= 15.66 milliseconds
25
ROOPESH KUMAR B N,CSE,KSIT
Non preemptive Scheduling Examples
Last Come First Served (LCFS)/Last In First Out (LIFO) Scheduling
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 (Assume only P1 is present in the ‘Ready’
queue when the scheduler picks up it and P2, P3 entered ‘Ready’ queue after
that). Now a new process P4 with estimated completion time 6ms enters the
‘Ready’ queue after 5ms of scheduling P1. 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).Assume all the processes contain only CPU operation and no I/O
operations are involved.
Average waiting time = (Waiting time for all processes) / No. of Processes
= (Waiting time for (P1+P4+P3+P2)) / 4
= (0 + 5 + 16 + 23)/4 = 44/4
= 11 milliseconds
27
ROOPESH KUMAR B N,CSE,KSIT
Turn Around Time (TAT) for P1 = 10 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P4 = 11 ms (Time spent in Ready Queue +
Execution Time = (Execution Start Time – Arrival Time) + Estimated Execution
Time = (10-5) + 6 = 5 + 6)
Turn Around Time (TAT) for P3 = 23 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P2 = 28 ms (Time spent in Ready Queue +
Execution Time)
Average Turn Around Time = (Turn Around Time for all processes) / No. of
Processes
= (Turn Around Time for (P1+P4+P3+P2)) / 4
= (10+11+23+28)/4 = 72/4
= 18 milliseconds
28
ROOPESH KUMAR B N,CSE,KSIT
Non preemptive Scheduling Examples
Shortest Job First (SJF) Scheduling (SOLVE)
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.
Priority based Scheduling
EXAMPLE: Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds and priorities 0, 3, 2 (0- 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.
30
ROOPESH KUMAR B N,CSE,KSIT
Preemptive Scheduling Examples
Preemptive SJF Scheduling/ Shortest Remaining Time (SRT)
EXAMPLE: Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds respectively enters the ready queue
together. A new process P4 with estimated completion time 2ms enters the
‘Ready’ queue after 2ms. Assume all the processes contain only CPU
operation and no I/O operations are involved.
Average waiting time = (Waiting time for all the processes) / No. of Processes
= (Waiting time for (P4+P2+P3+P1)) / 4
= (0 + 2 + 7 + 14)/4 = 23/4
= 5.75 milliseconds
32
ROOPESH KUMAR B N,CSE,KSIT
Turn Around Time (TAT) for P2 = 7 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P4 = 2 ms
(Time spent in Ready Queue + Execution Time = (Execution Start Time –
Arrival Time) + Estimated Execution Time = (2-2) + 2)
Turn Around Time (TAT) for P3 = 14 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P1 = 24 ms (Time spent in Ready Queue +
Execution Time)
Average Turn Around Time = (Turn Around Time for all the processes) / No. of
Processes
= (Turn Around Time for (P2+P4+P3+P1)) / 4
= (7+2+14+24)/4 = 47/4
= 11.75 milliseconds
33
ROOPESH KUMAR B N,CSE,KSIT
Preemptive Scheduling Examples
Round Robin (RR) Scheduling
EXAMPLE: Three processes with process IDs P1, P2, P3 with estimated
completion time 6, 4, 2 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) in RR algorithm
with Time slice= 2ms.
Average waiting time = (Waiting time for all the processes) / No. of Processes
= (Waiting time for (P1+P2+P3)) / 3
= (6+6+4)/3 = 16/3
= 5.33 milliseconds
35
ROOPESH KUMAR B N,CSE,KSIT
Turn Around Time (TAT) for P1 = 12 ms (Time spent in Ready Queue +
Execution Time)
Turn Around Time (TAT) for P2 = 10 ms (-Do-)
Turn Around Time (TAT) for P3 = 6 ms (-Do-)
Average Turn Around Time = (Turn Around Time for all the processes) / No. of
Processes
= (Turn Around Time for (P1+P2+P3)) / 3
= (12+10+6)/3 = 28/3
= 9.33 milliseconds.
37
ROOPESH KUMAR B N,CSE,KSIT
Explain the concept of Shared memory in detail?
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.
39
ROOPESH KUMAR B N,CSE,KSIT
Memory Mapped Objects: In this
approach, a mapping object is created
and physical storage for it is reserved
and committed.
Message Queue
Mailbox
Signaling
41
ROOPESH KUMAR B N,CSE,KSIT
Message Queue: 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.
Messages are sent and received through send and receive methods.
One task/process creates the mailbox and other tasks/process can subscribe to
this mailbox for getting message notification.
ROOPESH KUMAR B N, CSE,KSIT 43
Signaling
Signals are used for an asynchronous notification mechanism.
The signal mainly used for the execution synchronization of tasks process/ tasks.
Signals do not carry any data and are not queued.
The implementation of signals is OS kernel dependent
Hold & Wait: There must exist a process which holds some resource and waits
for another resource held by some other process.
No Resource Preemption: The criteria that Operating System cannot take back a
resource from a process which is currently holding it and the resource can only be
released voluntarily by the process holding it.
Circular Wait: All the processes must wait for the resource in a cyclic manner
where the last process waits for the resource held by the first process.
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' in behavior
Cost: This is the total cost for developing or buying the OS and maintaining it in
terms of commercial product
After Sales: For a commercial embedded RTOS, After Sales information must be
analyzed thoroughly.
ROOPESH KUMAR B N, CSE,KSIT 58
Embedded System Development Environment
PC acts as the master and target device acts as the slave in ISP. The program data
is sent to the MOSI pin of target device and the device acknowledgement is
originated from the MISO pin of the device. SCK pin acts as the clock for data
transfer.
ROOPESH KUMAR B N, CSE,KSIT 64
In Application Programming(IAP)
In Application Programming is a technique used by the firmware running on the
target device for modifying a selected portion of the code memory.
It is not a technique for first time embedding of user written firmware. It modifies
the program code memory under the control of the embedded application.
Updating calibration data, look-up tables, etc., which are stored in code memory,
are typical examples of IAP.
Use of Factory ProgrammedChip
It is possible to embed the firmware into the target processor/ controller memory
at the time of chip fabrication itself. Such chips are known as 'Factory Programmed
Chips'.
Once the firmware design is over and the firmware achieved operational stability,
the firmware files can be sent to the chip fabricator to embed it into the code
memory.
Firmware Loading for Operating System Based Devices: The OS based
embedded systems are programmed using the In System Programming (ISP)
technique. OS based embedded systems contain a special piece of code called 'Boot
loader' program which takes control of the OS and application firmware embedding
and copying of the OS image to the RAM of the system for execution.
What is BootROM?
A program which contains libraries for implementing In system Programming
which is embedded into the memory at the time of chip fabrication.
What is Bootloader?
Program which takes control of the OS and application firmware embedding and
copying of the OS image to the RAM.