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

Module 5 Notes

The document discusses the fundamentals of Real-Time Operating Systems (RTOS) and their architecture, including the role of the kernel, process management, memory management, and file system management. It differentiates between General Purpose Operating Systems (GPOS) and RTOS, highlighting the deterministic behavior of RTOS which is crucial for time-critical applications. Additionally, it covers the design approaches of monolithic and microkernel architectures, along with their respective advantages and drawbacks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Module 5 Notes

The document discusses the fundamentals of Real-Time Operating Systems (RTOS) and their architecture, including the role of the kernel, process management, memory management, and file system management. It differentiates between General Purpose Operating Systems (GPOS) and RTOS, highlighting the deterministic behavior of RTOS which is crucial for time-critical applications. Additionally, it covers the design approaches of monolithic and microkernel architectures, along with their respective advantages and drawbacks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

MODULE – 5

RTOS and IDE for


Embedded System Design
 Operating System Basics
 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.

 The primary functions of an operating system are:

o Make the system convenient to use


o Organise and manage the system resources
efficiently and correctly
 Figure gives an insight into the basic components of an operating system and
their interfaces with rest of the world.

User
Applications Application Program
Memory Management Interface(API)

Process Management
Time Management
File System Management
I/O System Management

Underlying Hardware Device Driver Interface

Fig: The Operating System Architecture


The 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.

• Kernel contains a set of system libraries and services.


• For a general purpose OS, the kernel contains different services for

handling the following:


• Process Management
• Primary Memory Management
• File System Management
• I/O System (Device) Management
• Secondary Storage Management
• Protection Systems
• Interrupt Handler

Process Management:
 Process management deals with managing the processes/tasks.

 Process management includes

o Setting up the memory space for the process

o Loading the process's code into the memory space


o Allocating system resources

o Scheduling and managing the execution of the process

o Setting up and managing the Process Control Block (PCB)

o Inter Process Communication and synchronisation

o Process termination/deletion, etc.

Primary Memory Management:


 The term primary memory refers to the volatile
memory (RAM) where processes are loaded and
variables and shared data associated with each
process are stored.
 The Memory Management Unit (MMU) of the kernel is
responsible for
o Keeping track of which part of the memory area is
currently used by which process
o Allocating and De-allocating memory
space on a need basis (Dynamic
memory allocation)

File System Management:


 File is a collection of related information.
o A file could be a program (source code or executable), text files,
image files, word
documents, audio/video files, etc.

 The file system management service of Kernel is responsible for


o The creation, deletion and alteration of files
o Creation, deletion and alteration of directories
o Saving of files in the secondary storage memory (e.g. Hard disk
storage)
o Providing automatic allocation of file space based on the amount
of free space available
o Providing a flexible naming convention for the files

 The various file system management operations are OS dependent.


o For example, the kernel of Microsoft DOS OS
supports a specific set of file system management
operations and they are not the same as the file
system operations supported by UNIX Kernel.

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.
 In a well-structured OS, the direct accessing of I/O devices are not
allowed and the access to them are provided through a set of
Application Programming Interfaces (APIs) exposed by the kernel.

 The kernel maintains a list of all the I/O devices of the system.
o May be available in advance or updated dynamically as and
when a new device is installed.
 The service Device Manager of the kernel is responsible for handling
all I/O device related operations.

 The kernel talks to the I/O device through a set of low-level systems
calls, which are implemented in a service called device drivers.

 Device Manager is responsible for


o Loading and unloading of device drivers
o 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.

• Secondary memory is used as backup medium for programs and


data since the main memory is volatile.
• In most of the systems, the secondary storage is kept in disks (Hard
Disk).

• The secondary storage management service of kernel deals with


o Disk storage allocation
o Disk scheduling (Time interval at which the disk is
activated to backup data)
o Free Disk space management

Protection Systems:
 Most of the modern operating systems are designed in such a way to
support multiple users with different levels of access permissions.
o E.g. ‘Administrator’, ‘Standard’, ‘Restricted’ permissions in
Windows XP.

 Protection deals with implementing the security policies to restrict the


access to both user and system resources by different applications or
processes or users.
 ln multiuser supported operating systems, one user may not be allowed
to view or modify the whole or portions of another user's data or
profile details.

 In addition, some application may not granted with permission to


make use of
some of the system resources.
 This kind of protection is provided by the protection services running
Interrupt Handler:
• Kernel provides handler mechanism for all external/internal interrupts
generated by the system.

Kernel Space and User Space:

• The applications/services are classified into two categories:

o User applications

o Kernel applications

• Kernel Space is the memory space at which the kernel code is


located
o Kernel applications/services are kept in this contiguous area
of primary (working) memory.
o It is protected from the unauthorised access by user
programs/applications.

• User Space is the memory area where user applications are loaded
and executed.

• The partitioning of memory into kernel and user space is purely OS

dependent.
o Some OS implement this kind of partitioning and
protection
whereas some OS do not segregate the kernel and user
application code storage into two separate areas.

• In an operating system with virtual memory support, the use


applications are loaded into its corresponding virtual memory
space with demand paging technique.
 The entire code for the user application need not
be loaded to the main (primary) memory at once.
 The user application code is split into different
pages and these pages are loaded into and out of
the main memory area on a need basis.
 The act of loading the code into and out of the main memory is
termed as
'Swapping’.
• Swapping happens between the main (primary) memory and
secondary storage memory.

Monolithic Kernel and Microkernel:


• The kernel forms the heart of an operating system.
• Different approaches are adopted for building an Operating
System kernel.
• Based on the kernel design, kernels can be classified into
o Monolithic Kernel
o Microkernel

Monolithic Kernel:
 In monolithic kernel architecture, all kernel services run in the kernel
space.
 Here all kernel modules run within the same memory space under a
single kernel thread.
 The tight internal integration of kernel modules in monolithic kernel
architecture allows the effective utilisation of the low-level features of
the underlying system.
 The major drawback of monolithic kernel is that any error or failure in
any one of the kernel modules leads to the crashing of the entire kernel
application.
 LINUX, SOLARIS, MS-DOS kernels are examples of monolithic
kernel.
 The architecture representation of a monolithic kernel is given in the
figure.
Applications

Monolithic kernel with all


operating system services running in kernel space

Fig: The Monolithic Kernel


Model

Microkernel:
• The microkernel design incorporates only the essential set of
Operating System services into the kernel.

• The rest of the Operating System services are implemented in


programs known as 'Servers' which runs in user space.

• This provides a 'highly modular design and OS-neutral abstract to


the kernel.

• Memory management, process management, timer systems and


interrupt handlers are the essential services, which forms the
part of the microkernel.
• Mach, QNX, Minix 3 kernels are examples for microkernel.
• The architecture representation of a microkernel is shown in the
figure.
Services (kernel
Applications
services running in user space)

Microkernel with essential


services like memory management, process management, timer system, etc.

Fig: The Microkernel


Model

 Microkernel based design approach offers the following benefits:


1. Robustness
1. If a problem is encountered in any of the services, which runs as
'Server' application, the same can be reconfigured and re-started

without the need for re- starting the entire OS.


2. Thus, this approach is highly useful for systems, which demands high
'availability’.

3. Since the services which run as 'Servers' are running on a


different
memory space, the chances of corruption of kernel
services are ideally zero.
2. Configurability
4. Any service which runs as 'Server' application can be changed
without
the need to restart the whole system.
5. This makes the system dynamically configurable.

 Types of Opearting Systems:


• Depending on the type of kernel and kernel service purpose and
type of computing systems where the OS is deployed and the
responsiveness to applications, Operating Systems are classified
into different types.
• General Purpose Operating System (GPOS)
• Real-Time Operating System (RTOS)

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 a GPOS 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.
o Their services can inject random delays into application software and
may cause slow responsiveness of an application at unexpected times.

 GPOS are usually deployed in computing systems where deterministic


behaviour is not an important criterion.

 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.

Real-Time Operating System (RTOS):


 'Real-Time' implies deterministic timing behaviour.
o 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.
o The RTOS decides which applications should run in which order and
how much time needs to be allocated for each application.
 Predictable performance is the hallmark of a well-designed RTOS.

 This is best achieved by the consistent application of policies and rules.


o Policies guide the design of an RTOS.
o Rules implement those policies and resolve policy conflicts.

 Windows CE, QNX, VxWorks, MicroC/OS-II, etc. are examples of Real-


Time Operating Systems (RTOS).

The Real-Time Kernel: The kernel of a Real-Time Operating System is


referred as Real-Time kernel.
• The Real-Time kernel is highly specialised and it contains only
the minimal set of services required for running the user
applications/tasks.
• The basic functions of a Real-Time kernel are:
• Task/Process Management
• Task/Process Scheduling
• Task/Process Synchronisation
• Error/Exception Handling
• Memory Management
• Interrupt Handling
• Time Management
1. Task/Process Management: Deals with
• setting up the memory space for the tasks
• loading the task's code into the memory space
• allocating system resources
• setting up a Task Control Block (TCB) for the task
• task/process termination/deletion
 A Task Control Block (TCB) is used for holding the information
corresponding to a task.
 TCB usually contains the following set of information:
 Task ID: Task Identification Number
 Task State: The current state of the task (e.g. State = 'Ready'
for a task which is ready to execute)
 Task Type: Indicates what is the type for this task. The task
can be a hard real time or soft real time or background task.
 Task Priority: Task priority (e.g. Task priority = 1 for task with priority = 1)
 Task Context Pointer: Pointer for context saving
 Task Memory Pointers: Pointers to the code memory, data
memory and stack memory for the task
 Task System Resource Pointers: Pointers to system
resources
(semaphores, mutex, etc.) used by the task
 Task Pointers: Pointers to other TCBs (TCBs for preceding,

next and waiting tasks)


 Other Parameters: Other relevant task
parameters
 The parameters and implementation of the TCB is kernel dependent.
 The TCB parameters vary across different kernels, based
on the task management implementation.
 Task management service utilises the TCB of a task in the following way:
 Creates a TCB for a task on creating a task
 Delete/remove the TCB of a task when the task is terminated or
deleted
 Reads the TCB to get the state of a task
 Update the TCB with updated parameters on need basis (e.g. on a
context switch)
 Modify the TCB to change the priority of the task dynamically
2. Task/Process Scheduling:
 Deals with sharing the CPU among various tasks/processes.
 A kernel application called 'Scheduler' handles the task
scheduling.
 Scheduler is nothing but an algorithm implementation, which
performs the efficient and optimum scheduling of tasks to
provide a deterministic behaviour.
3. Task/Process Synchronisation:
 Deals with synchronising the concurrent access of a resource,
which is shared across multiple tasks and the communication
between various tasks.
4. Error/Exception Handling
 Deals with registering and handling the errors
occurred/exceptions raised during the execution of tasks.
 Insufficient memory, timeouts, deadlocks, deadline missing, bus
error, divide by zero, unknown instruction execution, etc. are

examples of errors/exceptions.
 Errors/Exceptions can happen at the kernel level services or at
task level.
 Deadlock is an example for kernel level exception, whereas
timeout is an example for a task level exception.
 The OS kernel gives the information about the error in the form
of a system call (API).
 Watchdog timer is a mechanism for handling the timeouts for
tasks.
5. Memory Management:
 RTOS makes use of 'block' based memory allocation technique,
instead of the usual dynamic memory allocation techniques
used by the GPOS.
 RTOS kernel uses blocks of fixed size of dynamic memory and
the block is allocated for a task on a need basis.
 The blocks are stored in a 'Free Buffer Queue’.
 To achieve predictable timing and avoid the timing overheads,
most of the RTOS kernels allow tasks to access any of the
memory blocks without any memory protection.
 RTOS kernels assume that the whole design is proven correct
and protection is unnecessary.
 Some commercial RTOS kernels allow memory protection as
optional.
 A few RTOS kernels implement Virtual Memory concept for
memory allocation if the system supports secondary memory
storage (like HDD and FLASH memory).
 In the 'block' based memory allocation, a block of fixed
memory is always allocated for tasks on need basis and it is
taken as a unit.
 Hence, there will not be any memory fragmentation issues.
 The 'block' based memory allocation achieves deterministic
behavior with the trade of limited choice of memory chunk size
and suboptimal memory usage.
6. Interrupt Handling

 Deals with the handling of various types of interrupts.

 Interrupts provide Real-Time behaviour to systems.


 Interrupts inform the processor that an external device or an
associated task requires immediate attention of the CPU.
 Interrupts can be either Synchronous or Asynchronous.

 Synchronous interrupts:
 Occur in sync with the currently executing task.
 Usually the software interrupts fall under this category.
 Divide by zero, memory segmentation error, etc. are examples of
synchronous interrupts.
 For synchronous interrupts, the interrupt handler runs in the
same context of the interrupting task.
 Asynchronous interrupts:
o Occur at any point of execution of any task, and are not in
sync with the currently executing task.
o The interrupts generated by external devices (by asserting
the interrupt line of the processor/controller to which the
interrupt line of the device is connected) connected to the
processor/controller, timer overflow interrupts, serial data
reception/ transmission interrupts, etc. are examples for
asynchronous interrupts.
o For asynchronous interrupts, the interrupt handler is
usually written as separate task and it runs in a different
context.
o Hence, a context switch happens while handling the
asynchronous interrupts.
 Priority levels can be assigned to the interrupts and each
interrupt can be enabled or disabled individually.
 Most of the RTOS kernel implements 'Nested Interrupts'
architecture.
o Interrupt nesting allows the pre-emption (interruption)
of an Interrupt Service Routine (ISR), servicing an
interrupt, by a high priority interrupt.

7.Time Management:
 Accurate time management is essential for providing precise
time reference for all applications.
 The time reference to kernel is provided by a high-resolution
Real-Time Clock (RTC) hardware chip (hardware timer).
 The hardware timer is programmed to interrupt the
processor/controller at a fixed rate.
 This timer interrupt is referred as ‘Timer tick’ and is taken as the
timing reference by the kernel.
 The 'Timer tick' interval may vary depending on the hardware
timer.
 Usually the 'Timer tick' varies in the microseconds range.
 The time parameters for tasks are expressed as the multiples of
the ‘Timer tick'.
 The System time is updated based on the 'Timer tick’.
 If the System time register is 32 bits wide and the 'Timer tick'
interval is 1 microsecond, the System time register will reset in
 If the ‘Timer tick' interval is 1 millisecond, the system time
register will resent in
 The 'Timer tick' interrupt is handled by the 'Timer Interrupt'
handler of kernel.
 The 'Timer tick' interrupt can be utilised for implementing the
following actions:
 Save the current context (Context of the currently executing
task).
 Increment the System time register by one. Generate timing
error and reset the System time register if the timer tick count is
greater than the maximum range available for System time
register.
 Update the timers implemented in kernel (Increment or
decrement the timer registers for each timer depending on the
count direction setting for each register. Increment registers with
count direction setting = 'count up' and decrement registers with
count direction setting = 'count down').
 Activate the periodic tasks, which are in the idle state.
 Invoke the scheduler and schedule the tasks again based on the
scheduling algorithm.
 Delete all the terminated tasks and their associated data

structures (TCBs).
 Load the context for the first task in the ready queue. Due to
the re-scheduling, the ready task might be changed to a new
one from the task, which was preempted by the 'Timer
Interrupt'

You might also like