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

Rtes07 - Rtos

Uploaded by

mzmegastorm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Rtes07 - Rtos

Uploaded by

mzmegastorm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

EEE440

Real Time Embedded


Systems
Real Time Operating System
Muhammad Kamran Fiaz ([email protected])
We learned so far

 RTES Introduction
 Categories of the RTES
 Properties & Components
 Hardware
Today’s topics

 Real Time Operating System Concepts


Introduction

 The heart of many computerized embedded systems.


 An RTOS is an operating system that supports
 the construction of applications that must meet real-time constraints
 providing logically correct computation results.
 Mechanisms and services to carry out
 real-time task scheduling
 resource management
 intertask communication.
General Purpose Operating System

 An operating system (OS) is the software that sits between the hardware of a
computer and software applications running on the computer. An OS is a
resource allocator and manager.
 It manages the computer hardware resources and hides the details of how the
hardware operates to make the computer system more convenient to use.
 The main hardware resources in a computer are
 Processor
 Memory
 I/O controllers
 Disks
 and other devices such as terminals and networks.
General Purpose Operating System

 An OS is a policy enforcer.
 It defines the rules of engagement between the applications and resources and
controls the execution of applications to prevent errors and improper use of the
computer.
 An OS is composed of multiple software components, and the core
components in the OS form its kernel.
 The kernel provides the most basic level of control over all of the computer’s
hardware devices.
 The kernel of an OS always runs in system mode, while other parts and all
applications run in user mode.
 Kernel functions are implemented with protection mechanisms such that they
could not be covertly changed through the actions of software running in
userspace.
General Purpose Operating System

 The OS also provides an Application Programming Interface (API)


 API defines the rules and interfaces that enable applications to use OS features and
communicate with the hardware and other software applications.
 User processes can request kernel services through system call or by message passing.
 With the system call approach, the user process applies traps to the OS routine that
determines which function is to be invoked, switches the processor to system mode,
calls the function as a procedure, and then switches the processor back to user mode
when the function completes and returns control to the user process.
 In the message passing approach, the user process constructs a message that
describes the desired service and then uses a send function to pass it to an OS
process. The send function checks the desired service specified in the message,
changes the processor mode to system mode, and delivers it to the process that
implements the service. Meanwhile, the user process waits for the result of the service
request with a message receive operation. When the service is completed, the OS
process sends a message back to the user process.
Functions of the General Purpose OS

 Process Management
 Memory Management
 Interrupts Management
 Multitasking
 File System Management
 I/O Management
Process Management

 A process is an instance of a program in execution. It is a unit of work within the


system.
 A process needs resources, such as CPU, memory, I/O devices, and files, to
accomplish its task.
 Starting a new process is a heavy job for the OS, which includes allocating
memory, creating data structures, and coping code.
 A thread is a path of execution within a process and the basic unit to which the
OS allocates processor time.
 A process can be single-threaded or multithreaded.
 The essential difference between a thread and a process is the work that each one is
used to accomplish. Treads are used for small tasks, whereas processes are used for
more heavyweight tasks – basically the execution of applications. Therefore, a thread
is often called a lightweight process.
Process Management
Process Management

 Fork
 Spawn
 PID (Process Identifier)
 Exit
 Suspension

 Inter process Communication (IPC)


 Files
 Sockets
 Pipes
Memory Management

 Main memory is the most critical resource in a computer system in terms of


speed at which programs run.
 The kernel of an OS is responsible for all system memory that is currently in
use by programs. Entities in memory are data and instructions.
 Each memory location has a physical address. In most computer
architectures, memory is byte-addressable, meaning that data can be
accessed 8 bits at a time, irrespective of the width of the data and address
buses.
 Memory addresses are fixed-length sequences of digits. In general, only
system software such as Basic Input/Output System (BIOS) and OS can
address physical memory.
Memory Management

 Most application programs do not have knowledge of physical addresses.


 Instead, they use logic addresses. A logical address is the address at which
a memory location appears to reside from the perspective of an executing
application program.
 A logical address may be different from the physical address due to the
operation of an address translator or mapping function.
 In a computer supporting virtual memory, the term physical address is used
mostly to differentiate from a virtual address.
 In particular, in computers utilizing a memory management unit (MMU) to
translate memory addresses, the virtual and physical addresses refer to an
address before and after translation performed by the MMU, respectively.
Memory Management

 Program Execution
 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.
 To create a load module, the source code is compiled
by the compiler. The compiler produces an object
module.
Memory Management

 Dynamic Memory Allocation


 Heap
 Stack
 Dynamic Linking/ Dynamic Loading
Interrupts Management

 An interrupt is a signal from a device attached to a computer or from a running


process within the computer, indicating an event that needs immediate
attention.
 The processor responds by suspending its current activity, saving its state, and
executing a function called an interrupt handler (also called interrupt service
routine, ISR) to deal with the event.
 Modern OSs are interrupt-driven. Virtually, all activities are initiated by the arrival
of interrupts. Interrupt transfers control to the ISR, through the interrupt vector,
which contains the addresses of all the service routines.
 Interrupt architecture must save the address of the interrupted instruction.
 Incoming interrupts are disabled while another interrupt is being processed.
 A system call is a software-generated interrupt caused either by an error or by a user
request.
Multitasking

 Real-world events may occur simultaneously.


 Multitasking refers to the capability of an OS that supports multiple
independent programs running on the same computer.
 It is mainly achieved through time-sharing, which means that each
program uses a share of the computer’s time to execute.
 How to share processors’ time among multiple tasks is addressed by
schedulers, which follow scheduling algorithms to decide when to execute
which task on which processor.
Multitasking - Scheduling

 Each task has a context, which is the data indicating its execution state
and stored in the task control block (TCB), a data structure that contains all
the information that is pertinent to the execution of the task.
 When a scheduler switches a task out of the CPU, its context has to be
stored; when the task is selected to run again, the task’s context is restored
so that the task can be executed from the last interrupted point.
 The process of storing and restoring the context of a task during a task
switch is called a context switch.
Multitasking – Context Switching
File System Management

 Files are the fundamental abstraction of secondary storage devices. Each


file is a named collection of data stored in a device. An important
component of an OS is the file system, which provides capabilities of file
management, auxiliary storage management, file access control, and
integrity assurance.
 File management is concerned with providing the mechanisms for files to
be stored, referenced, shared, and secured.
 When a file is created, the file system allocates an initial space for the data.
Subsequent incremental allocations follow as the file grows.
 When a file is deleted or its size is shrunk, the space that is freed up is
considered available for use by other files
File System Management
I/O Management

 Modern computers interact with a wide range of I/O devices. Keyboards, mice, printers, disk drives, USB
drives, monitors, networking adapters, and audio systems are among the most common ones.
 One purpose of an OS is to hide peculiarities of hardware I/O devices from the user.
 Memory-mapped I/O
 Each I/O device occupies some locations in the I/O address space.
 Communication between the I/O device and the processor is enabled through physical memory locations in the I/O
address space.
 By reading from or writing to those addresses, the processor gets information from or sends commands to I/O devices.
 Device Controllers
 A device controller is primarily an interface unit. The OS communicates with the I/O device through the device
controller.
 Nearly all device controllers have direct memory access (DMA) capability, meaning that they can directly access the
memory in the system, without the intervention by the processor. This frees up the processor of the burden of data
transfer from and to I/O devices.
I/O Management

 Interrupts allow devices to notify the processor when they have data to
transfer or when an operation is complete, allowing the processor to perform other duties
when no I/O transfers need its immediate attention.
 The processor has the interrupt request line that it senses after executing every instruction.
 Device Controller raises an interrupt
 Processor catches it, saves its state and transfer control to the ISR
 ISR determines the cause of the interrupt and perform necessary processing.
 I/O operations often have high latencies. Most of this latency is due to the
slow speed of peripheral devices.
 For example, information cannot be read from or written to a hard disk until the spinning of
the disk brings the target sectors directly under the read/write head.
 The latency can be alleviated by having one or more input and output buffers associated
with each device.
RTOS Kernel

 Why General Purpose OS not workable in real time embedded systems?


 it takes too much space and contains too many functions that may not be
necessary for a specific real-time application.
 It is not configurable, and its inherent timing uncertainty offers no guarantee to
system response time.
 Therefore, a general-purpose OS is not suitable for real-time embedded systems

 We need RTOS for real time systems


Characteristics of RTOS Design

 The timing behavior of the OS must be predictable. For all services provided
by the OS, the upper bound on the execution time must be known. Some
of these services include OS calls and interrupt handling.
 The OS must manage the timing and scheduling, and the scheduler must
be aware of task deadlines.
 The OS must be fast. For example, the overhead of context switch should
be short. A fast RTOS helps take care of soft real-time constraints of a system
as well as guarantees hard deadlines
RTOS Overview
RTOS Kernel

 A real-time kernel is software that manages the time and resources of a


microprocessor or microcontroller and provides indispensable services such
as task scheduling and interrupt handling to applications.
 In embedded systems, a small amount of code called board support
package (BSP) is implemented for a given board that conforms to a given
OS. It is commonly built with a bootloader that contains the minimal device
support to load the OS and device drivers for all the devices on the board.
RTOS Kernel
Clocks and Timers

 Hardware Timer to interrupt when the required time is up


 taskDelay ()
Scheduling

 Priority Scheduling
 EDF
 RM
 Preemption
Scheduling

 First Come First Serve


 Round Robin

 Are these above schemes applicable for Real Time Systems


Inter-Task Communication

 A task can not call another task


 Tasks exchange information
 Through message passing
 Through memory sharing
 Real time signals
 Mutex
 Semaphore objects
Discussion Quiz

 What is the kernel of an operating system? In which mode does it run?


 What are the two approaches that a user process interacts with the
operating system? Discuss the merits of each approach.
 What is the difference between a program and a process? What is the
difference between a process and a thread?
 Should terminating a process also terminate all its children? Give an
example when this is a good idea and another example when this is a bad
idea.

You might also like