Real Time Operating System
Real Time Operating System
2 23 ، نيسان05
05نيسان23 ، 3
Process Management
A process is an instance of a program in execution.
A program is a passive entity , a process is an active entity
A process needs resources(CPU, memory, I/O devices, files)
Processes are used for more heavyweight tasks
A thread is a path of execution within a process
Threads are used for small tasks
Threads within the same process share the same address space
A thread managed independently by the scheduler
Processes may create other processes through appropriate system calls
A process can be single-threaded or multithreaded.
23 ، نيسان05 4
The process that does the creating is called parent of the other process ,called child
Each process is assigned a unique integer identifier
interprocess communication (IPC)
mechanisms to support IPC. Files, sockets, message queues, pipes, semaphores, shared
memory, and message passing
23 ، نيسان05 5
Memory Management
The kernel of an OS is responsible for all system memory .
Entities in memory are data and instructions.
Each memory location has a physical address.
memory is byte-addressable data
only system software such as Basic Input/output System (BIOS) and OS can address physical
memory
Most application programs do not have knowledge of physical addresses
The virtual memory technique, can ensure that each process is running in its own
dedicated address space.
Before a program is loaded into memory by the loader, part of the OS, It must be converted
into a load module and stored on disk.
23 ، نيسان05 6
The compiler produces an object module
Header records the size of each of the sections that follow.
Machine code section contains the executable instructions
compiled by the compiler.
Initialized data contains all data used by the program that require
initialization
The symbol table contains all external symbols used in the program.
Relocation information is used by the linker to
combine several object modules into aload module.
23 ، نيسان05 7
When a process is started, the OS allocates
memory to the process.
To avoid loading big executable files into
memory, modern OS provides two services:
dynamic loading and dynamic linking
single contiguous allocation such as MS-DOS
system
Paged allocation divides memory into fixed-size
units called page frames and The program’s virtual
address space into pages of the same size
23 ، نيسان05 8
Interrupts Management
An interrupt is a signal from a device
The processor responds by suspending its current activity, saving
its state, and executing a function called an interrupt handler
Modern OSs are interrupt-driven.
Incoming interrupts are disabled while another interrupt is being processed.
23 ، نيسان05 9
Multitasking
Multitasking refers to the capability of an OS that supports multiple independent programs
running on the same computer.
Each task has a context, which is the data indicating
its execution state andstored in the task control block (TCB)
context switch :The process of storing and
restoring the context of a task during a task
switch
23 ، نيسان05 10
File System Management
file system is an important component of an OS
file is created and there is not an area of contiguous space available for its initial allocation
A file system stores information for each file, size of data, the time the file was last
modified , user ID and group ID, and access permissions
File access control can be realized using a two-dimensional matrix
Role-based access control (RBAC) is an access control method where access to data is
performed by authorized users
23 ، نيسان05 11
I/O Management
Communication between the I/O device and the processor is enabled through physical
memory locations in the I/O address space
The OS communicates with the I/O device through the device controller.
all device controllers have direct memory access (DMA)capability
I/O operations often have high latencies .
The latency can be alleviated by having one or more input and output buffers associated
with each device.
23 ، نيسان05 12
Characteristics of RTOS Kernels
There are three key requirements of RTOS design
Firstly, the timing behavior of the OS must be predictable.
Secondly, the OS must manage the timing and scheduling, and the scheduler must be
aware of task deadlines
Thirdly, the OS must be fast.
23 ، نيسان05 13
Clocks and Timers
The RTOS works by setting up a hardware timer to interrupt periodically
The timer is often called a heartbeat timer , the interrupt is also called clock interrupt
In the POSIX standard, each tick is equal to 10 milliseconds
At each clock interrupt, an ISR increments tick count, checks to see if it is
now time to unblock or wake up a task.
POSIX specified several timer-related routines, including the following:
oTimer _ create()
o timer _ delete()
oTimer _ gettime()
oTimer _ getoverrun()
oTimer _ settime()
oNanosleep()
23 ، نيسان05 14
Priority Scheduling
real-time tasks have deadlines
Tasks with shorter deadlines , should be scheduled for execution sooner than those with
longer deadlines.
preemptive
23 ، نيسان05 15
Real Time Operating system
tasks exchange information through message passing or memory sharing
access to shared data using real-time signals, mutex , or semaphore objects.
Real-Time Signals :Signals are similar to software interrupts
Signals are also used for many other synchronous and asynchronous notifications
Semaphores are counters used for controlling access to resources shared among processes
or threads
There are two basic operationson semaphores:
1. One is to atomically increment the counter.
2. The other is to wait until the counter is nonnull and atomically decrement it
A semaphore tracks only how many resources are free
23 ، نيسان05 16
Message Passing
tasks can share data by sending messages in an organized message passing scheme
Message contents can be anything that is mutually comprehensible between the two
parties in communication.
Two basic operations are send and receive.
Message passing can be direct or indirect
Message passing can also be synchronous or asynchronous
23 ، نيسان05 17
Shared Memory
A method that an RTOS uses to map common physical space into independent process-
specific virtual space.
Shared memory is used to share information between different processes or threads.
it is necessary to use mutex or semaphores to protect the memory area.
A side effect in using shared memory is that it may cause priority inversion.
23 ، نيسان05 18
Asynchronous I/O
There are two types of I/O synchronization :
synchronous I/O
Synchronous I/O is desirable when the I/O operation is fast
asynchronous I/O
used to improve throughput , latency, and/or responsiveness.
23 ، نيسان05 19
Memory Locking
Memory locking is a real-time capability specified by POSIX .
allows fine-grained control of which part of the application must stay in physical memory
to reduce the overhead associated with transferring data between memory and disk.
When the process exits, the locked memory is automatically unlocked.
Defined mlock() and munlock() functions to lock and unlock memory.
More than one process can lock the same or overlapping region, and in that
case
the memory region remains locked until all the processes have unlocked it
23 ، نيسان05 20
Types of Real time operating system
Hard Real Time
In a hard RTOS, deadlines are so tight that the execution of specific tasks must start at a
specific scheduled time and be completed within the allotted time. Suppose the task is
to be completed at the 5th second, then it should not be completed before or after the
5th second and instead on the exact 5th second.
example of an airbag that a car
23 ، نيسان05 21
Soft Real Time
A soft real-time RTOS tolerates operating system delays. This type of RTOS gives deadlines to
certain jobs but can tolerate small-time delays. Therefore, this type of RTOS handles deadlines
gracefully. But yes, if the deadline is missed multiple times, that can lead to system failure.
Examples:
A video game is an example of a soft real-time system.
Automated teller machine (ATM)
23 ، نيسان05 22
Features of RTOS
Here are important features of RTOS:
Occupy very less memory
Consume fewer resources
Response times are highly predictable
Unpredictable environment
The Kernel saves the state of the interrupted task ad then determines which task it should
run next.
Disadvantages of RTOS
RTOS system can run minimal tasks together
Plenty of resources are used by RTOS, which makes this system expensive.
It uses complex algorithms which is difficult to understand.
23 ، نيسان05 23
RTOS Examples
LynxOS
OSE
QNX
VxWorks
23 ، نيسان05 24