CHP4 Notes
CHP4 Notes
Kernel contains
The super loop type application program, executes the a set of system libraries and services.
tasks sequentially in the order, and execution is non-real TYPES OF OPERATING SYSTEMS
time. As the number of task increases, the time intervals Depending on the type of kernel and kernel services,
at which a task gets serviced also increases. This type of purpose and type of computing systems where the OS is
firmware execution is suited for embedded devices deployed and the responsiveness to applications,
where response time for a task is not time critical, like Operating Systems are classified into different types.
electronic toys and video gaming devices. Certain General Purpose Operating System (GPOS)
applications demand time critical response, Flight The operating systems, which are deployed in general
Control systems, Air bag control and Anti-lock Brake computing systems, are referred as General Purpose
System (ABS) systems for vehicles, Nuclear monitoring Operating Systems ( GPOS). The kernel of such an OS
devices, etc. The approach is
is more generalised and it contains all kinds of services
1. Assign priority to tasks and execute the high priority
task when the task is ready to execute. required for executing generic applications, which are
2. Dynamically change the priorities of tasks if required not very critical. Their services can inject random
on a need basis. delays into application software and may cause slow
3. Schedule the execution of tasks based on the responsiveness of an application at unexpected times.
priorities. Personal Computer/Desktop system is a typical example
4. Switch the execution of task when a task is waiting for a system where GPOSs are deployed. Windows
for an external event or a system resource including I/O
10/8.x/XP/MS-DOS etc are examples.
device operation.
The use of operating system based firmware execution
Real-Time Operating System (RTOS)
in embedded devices can address these needs to a „Real-Time‟ implies deterministic timing behavior-
greater extent. means the OS services consumes only known and
expected amounts of time regardless the number of
OPERATING SYSTEM BASICS
The operating system acts as a bridge between the user services. A Real-Time Operating System or RTOS
applications/tasks and the underlying system resources implements policies and rules concerning time-critical
through a set of system functionalities and services. The allocation of a system‟s resources. Predictable
OS manages the system resources and makes them performance is the hallmark of well-designed RTOS.
available to the user applications/tasks on a need basis. Windows Embedded Compact, QNX, VxWorks
The primary functions of an operating system is MicroC/OS-II etc are examples of Real Time Operating
Make the system convenient to use.
Systems (RTOS).
Organise and manage the system resources efficiently
and correctly. Compare general purpose OS and Real-time OS
GPOS ( General purpose RTOS ( Real time
operating system ) operating system )
GPOS has fair scheduling RTOS has unfair
i.e it can be adjusted scheduling i.e
dynamically for scheduling is based on
optimized throughput. priority.
Kernel is pre-emptive
either completely or up
to maximum degree.
Kernel is non-preemptive pre-emptive – Stops
current task for high
priority tasks
The Kernel Task deadlines are not Task deadlines are
The kernel is the core of the operating system and is there in GPOS. present in RTOS.
responsible for managing the system resources and the Time response of OS is
communication among the hardware and other system Time response of OS is
deterministic
services. Kernel acts as the abstraction layer between not deterministic.
It is used for general It is used for dedicated files, word documents, audio/video files, etc. Each
universal applications. electronics applications. of these files differ in the kind of information they
It does not have a large hold and the way in which the information is
It has a large memory
memory. stored. The file operation is a useful service
GPOS ( General purpose RTOS ( Real time provided by the OS. Examples - Creation, deletion
operating system ) operating system ) and alteration of directories saving of fi les in the
Behaviour of GPOS is Behaviour of RTOS is
secondary storage memory (e.g. hard disk storage)
not predictable. predictable.
4. I/O System (Device) Management
Depending on
Depending on application Kernel is responsible for routing the I/O requests
application we can
we cannot customize coming from different user applications to the
customize RTOS.
GPOS. (No scalable.) appropriate I/O devices of the system. In a well-
(Scalable.)
It does not optimizes the It optimises the memory structured OS, the direct accessing of I/O devices
memory resources. resources. are not allowed and the access to them are provided
GPOS has high interrupt RTOS has low interrupt through a set of Application Programming
latency. latency. Interfaces (APIs)
It is normally stored in 5. Secondary Storage Management
It is normally stored in semiconductor memory The secondary storage management deals with
Hard disk. like EEPROM, Flash managing the secondary storage memory devices,
EEPROM if any, connected to the system. Secondary memory
is used as backup medium for programs and data
The Real-Time Kernel since the main memory is volatile. In most of the
The kernel of a Real-Time Operating System is referred systems, the secondary storage is kept in disks
as Real Time kernel. Real-Time kernel is highly (Hard Disk).
specialised and it contains only the minimal set of 6. Protection Systems
services required for running the user applications/tasks.
Most of the modern operating systems are designed
Functions of kernel or components of kernel
in such a way to support multiple users with
1. Process Management - different levels of access permissions (e.g.
Process management deals with managing the Windows 10 with user permissions like
processes/tasks. It includes setting up the memory „Administrator‟, „Standard‟, „restricted‟, etc.).
space for the process, loading the process‟s code Protection deals with implementing the security
into the memory space, allocating system policies to restrict the access
resources, scheduling and managing the execution
of the process, setting up and managing the Process TASK,PROCESS AND THREADS
Control Block (PCB), Inter Process
Communication and synchronization, process A program can be described as any executable file.
termination. Basically it contains certain set of instructions written to
2. Primary Memory Management perform a specific operation. It resides in Memory & is
The term primary memory refers to the volatile a passive entity which doesn‟t go away when system
memory (RAM) where processes are loaded and reboots.
variables and shared data associated with each
process are stored. The Memory Management Unit Process can be described as a program under
(MMU) of the kernel is responsible for Keeping execution. 1 program can have N processes. Process
resides in main memory & hence disappears whenever
track of which part of the memory area is currently
machine reboots. Multiple processes can be run in
used by which process allocating and De-allocating parallel on a multiprocessor system.
memory space on a need basis (Dynamic memory
allocation). Thread is described as a lightweight process. 1 process
3. File System Management can have N threads. All threads which are associated
File is a collection of related information. A fi le with a common process share same memory as of
could be a program (source code), text files, image process.
Multiprocessing The Last-Come-First Served (LCFS) scheduling
Multiprocessing describes the ability to execute algorithm also allocates CPU time to the processes
multiple processes simultaneously. Systems which are based on the order in which they are entered in the
„Ready‟ queue. The last entered process is serviced
capable of performing multiprocessing, are known as
first. LCFS scheduling is also known as Last In First
multiprocessor systems. Multiprocessor systems possess Out ( LIFO) where the process, which is put last into
multiple CPUs and can execute multiple processes the „Ready‟ queue, is serviced first.
simultaneously. Shortest Job First (SJF) Scheduling
Multitasking Shortest Job First (SJF) scheduling algorithm „sorts the
Multitasking refers to the simultaneously performance „Ready‟ queue‟ each time a process relinquishes the
of multiple tasks and processes by hardware, software CPU to pick the process with shortest (least) estimated
or any computing appliance. It enables the performance completion/run time. In SJF, the process with the
of more than one computer process at the same time shortest estimated run time is scheduled first, followed
with minimal lag in overall performance and without by the next shortest process, and so on.
affecting the operations of each task. Multitasking Priority Based Scheduling
involves the switching of CPU from executing one task Priority based non-preemptive scheduling algorithm
to another, using a scheduler. Whenever a CPU ensures that a process with high priority is serviced at
switching happens, the current context of execution the earliest compared to other low priority processes in
should be saved to retrieve it at a later point of time the „Ready‟ queue. The priority of a task/process can be
when the CPU executes the process, which is indicated through various mechanisms. Like attaching a
interrupted currently due to execution switching. The priority number to task or assign high priority to a short
act of saving the current context which contains the program, which depends on the kernel level
context details (Register details, memory details, system implementation of the priority structure.
resource usage details, execution details, etc.) for the Preemptive Scheduling
currently running process at the time of CPU switching In preemptive scheduling, every task in the „Ready‟
is known as „Context saving‟. The process of retrieving queue gets a chance to execute, dependent on the type
the saved context details for a process, which is going to of preemptive scheduling algorithm used. The
be executed due to CPU switching, is known as scheduler can preempt (stop temporarily) the currently
„Context retrieval‟. executing task/process and select another task from the
„Ready‟ queue for execution based on scheduling
TASK SCHEDULING algorithm. The two important approaches adopted in
Determining which task/process is to be executed at a preemptive scheduling are time-based preemption and
given point of time is known as task/process scheduling. priority-based preemption.
Task scheduling forms the basis of multitasking. Preemptive SJF Scheduling/ Shortest Remaining
Scheduling policies are implemented in an algorithm Time (SRT)
and it is run by the kernel as a service. The kernel The preemptive SJF(Shortest Job First) scheduling
service/application, which implements the scheduling algorithm sorts the „Ready‟ queue , when a new process
algorithm, is known as „Scheduler‟. enters the „Ready‟ queue , and if the execution time of
Types of scheduling the new process is less, the currently executing process
Non-preemptive Scheduling is preempted and the new process is scheduled for
Non-preemptive scheduling is employed in systems, execution. Also known as Shortest Remaining Time (
which implement non-preemptive multitasking model. SRT) scheduling.
In this scheduling type, the currently executing Round Robin Scheduling
task/process is allowed to run until it terminates or The term Round Robin means “Equal chance to all”.
enters the „Wait‟ state waiting for an I/O or system Each process in the „Ready‟ queue is executed for a
resource.
pre-defined time slot. The sequence is repeated.
First-Come-First-Served (FCFS)/ FIFO Scheduling
As the name indicates, the First-Come-First-Served ( Priority Based Scheduling
FCFS) scheduling algorithm allocates CPU time to the
processes based on the order in which they enter the In preemptive scheduling, any high priority process
„Ready‟ queue. The first entered process is serviced entering the „Ready‟ queue is immediately scheduled
first. for execution whereas in the non-preemptive scheduling
Last-Come-First Served (LCFS)/LIFO Scheduling any high priority process entering the „Ready‟ queue is
scheduled only after the currently executing process
completes its execution or only when it voluntarily thread. If a thread acquires a mutex, the second thread
relinquishes the CPU. that wants to acquire that mutex is suspended until the
TASK COMMUNICATION first thread releases the mutex. It is just like keys
In a multitasking system, multiple tasks/processes run at 3. Semaphore:
the same time, and each process may or may not In computer science, a semaphore is a variable or
interact between. These processes are classified as abstract data type used to control access to a common
resource by multiple tasks. Semaphores are used to
Co-operating Processes: In the co-operating manage and protect access to shared resources.
interaction model one process requires the inputs from Semaphores are very similar to Mutexes. Whereas a
other processes to complete its execution. Mutex permits just one thread to access a shared
Competing Processes: The competing processes do not resource at a time, a semaphore can be used to permit a
share anything among themselves but they share the fixed number of threads to access a pool of shared
system resources, such as file, display device, etc. resources.
Co-operating processes exchanges information and 4. Spinlock:
communicate through Sharing, and through Spinlock keeps the task in a loop repeatedly checking
Communication: whether the resource is free
The mechanism through which processes/tasks 5. Read/write locks –
communicate each other is known as Inter Process/Task An RW lock allows simultaneous access for read-only
Communication ,which is essential for process co- operations, whereas write operations require exclusive
ordination. access
Task synchronization Device driver
In a multitasking environment, multiple processes run Device driver is a piece of software that acts as a bridge
concurrently (in pseudo parallelism) and share the between the operating system and the hardware. All the
system resources. The main objective of task device related access should flow through the OS kernel
synchronization is to ensure that multiple tasks or and the OS kernel routes it to the concerned hardware
processes access shared resources without interfering peripheral.
with each other. It also prevent the possibility of error in Device drivers are responsible for initiating and
data due to simultaneous access. To achieve this, managing the communication with the hardware
various synchronization techniques are used. peripherals.
• Process/Task synchronization is essential for An embedded product may contain different types of
1. Avoiding conflicts in resource access (racing, hardware components like Wi-Fi module, File systems,
deadlock) Storage device interface, etc. ,and a single driver will
2. Ensuring proper sequence of operation across not be able to satisfy all these.
processes. Certain drivers come as part of the OS kernel and
3. Communicating between processes/tasks certain drivers need to be installed. If an external
4. Avoiding race condition – two task competing for a device, whose driver software is not available with OS
resource kernel image, OS prompts the user to install its driver
5. Avoiding dead-lock - deadlock condition creates a manually.
situation where none of the processes are able to make Selection criteria for RTOS
any progress in their execution RTOS are selected on the basis of functional or
Task Synchronization Techniques – nonfunctional factors.
1. Mutual exclusion – Functional Requirements
Different tasks may have to share same resources; for 1. Processor Support - It is not necessary that all
example two tasks may have to share a printer. We can RTOS‟s support all kinds of processor architecture. It is
imagine what would happen if two tasks send data essential to ensure the processor support by the RTOS.
simultaneously to a printer. It will cause in a random 2. Memory Requirements - The OS requires ROM
printout. Tasks should maintain discipline to share the memory for holding the OS files and also requires
resources, ensuring that two of more tasks access a working memory RAM for loading the OS services. it is
shared resource without corrupting the data is called essential to evaluate the minimal ROM and RAM
mutual exclusion. requirements for the OS under consideration.
2. Mutex:- 3. Real-time Capacities - Analyze the real-time
Mutex is a synchronization function that grants capabilities of the OS under consideration and ensure
exclusive access to the shared resource to only one that it meets our standards.
4. Kernel and Interrupt Latency - The kernel of the Micro C/OS-II is a multitasking operating system. Each
OS may disable interrupts while executing certain task is in an infinite loop and can be in any one of the
services and it may lead to interrupt latency. For an following five states: Dormant, Ready, Running,
embedded system whose response requirements are Waiting ISR (Interrupt Service Routine). Task Creation:
high, this latency should be minimal. There are two functions for creating a task:
5. Inter Process Communication and Task OSTaskCreate() & OSTaskCreateExt(). It can manage
Synchronization – some operating system provide upto 64 tasks. It uses rate priority based rate-monotonic
many options for Inter Process Communication and scheduling
Synchronization whereas others provide very limited 2. Task scheduling
options. The MicroC/OS-II support preemptive priority based
6. Modularization Support – certain embedded project scheduling. Each task should be assigned a unique
may not require all the features of the operating system. priority ranging from 0 to 63 with 0 being the highest
In such cases, such functions can be removed from the priority level. When the kernel starts, it executes the
operating system to reduce the size. first available highest priority task.
7. Support for Networking and Communication - 3. Inter-Task Communication
Ensure that the OS under consideration provides The MicroC/OS-II kernel supports the following inter-
support for all the interfaces required by the embedded process communication techniques for data sharing and
product. co-operation among tasks 1. Mailbox 2. Message queue
Non-functional Requirements are some methods used for inter task communication.
4. Task Synchronization
8. Cost - The total cost for buying the OS may increase In a multitasking environment, multiple processes run
the overall product cost. While selecting the operating concurrently (in pseudo parallelism) and share the
system, its cost should also be considered. system resources. The main objective of task
9. Development and Debugging Tools Availability - synchronization is to ensure that multiple tasks or
Certain Operating Systems may be superior in processes access shared resources without interfering
performance, but the availability of tools for supporting with each other. It also prevent the possibility of error in
the development may be limited. Explore the different data due to simultaneous access. In The MicroC/OS-II ,
tools available for the OS under consideration. mutex and semaphores are used for task
10. Ease of Use - How easy it is to use a commercial synchronization . These are like keys to access
RTOS is another important feature that needs to be recourses.
considered in the RTOS selection. 5. Memory Management
11. After Sales - For a commercial embedded RTOS, In operating systems, memory management function is
after sales in the form of e-mail, on-call services, etc. responsible for managing the computer's primary
for issues is must. memory. The memory management function keeps
track of the status of each memory location, either
Overview of Micro C/OS-II and its services allocated or free.
• MicroC/OS-II is the short form of Micro-Controller 6. The services of Memory management includes:
Operating Systems Version 2. Initializing the Memory Manager, Creating a Memory
• It is a priority-based real-time multitasking operating Partition, Obtaining Status of a Memory Partition,
system kernel for microprocessors Obtaining a Memory Block, Loading the task to the
• It is written mainly in the C programming language. memory, after completion of the task, the memory
• It is intended for use in embedded systems. block is made free by terminating the task.
• It is a very small real-time kernel.
• Memory size (RAM) requirement is about 20KB List popular Real Time Operating Systems
• Highly portable, very scalable, preemptive real-time; 1. µC/OS
deterministic, multitasking kernel. 2. VxWorks
• It can manage up to 64 tasks 3. Deos
• It has support for more than 100 microprocessors and 4. FreeRTOS (Amazon)
microcontrollers. 5. Integrity
• It is simple to use and simple to implement and very 6. Keil RTX (ARM)
effective compared to the price/performance ratio. 7. MQX (Philips)
• It supports all type of processors from 8-bit to 64-bit. 8. Nucleus (Mentor Graphics)
Micro C/OS-II services 9. Neutrino (BlackBerry)
1. Task Creation and Management 10. SafeRTOS (Wittenstein)