Unit 3 and Unit 4 (2 Files Merged)
Unit 3 and Unit 4 (2 Files Merged)
Real Time System Hard and Soft Real Time Systems (Operational Definition)
A system is said to be Real Time if it is Hard Real Time System Hard Real Time System
required to complete it’s work & deliver Failure to meet deadlines is fatal Validation by provably correct procedures or
example : Flight Control System extensive simulation that the system always meets
it’s services on time.
Microkernel Exokernel
It runs only services protecting the
AmigaOS and resources (i.e. tracking the ownership,
An RTOS generally avoids implementing the
guarding the usage, revoking kernel as a large monolithic program. The
QNX access to resources, etc) by providing low-level interface for library operating
systems and leaving the
kernel is developed instead as a micro-kernel
management to the application. with added configurable functionalities.
This implementation gives resulting benefit in
increase system configurability, as each
embedded application requires a specific set
of system services with respect to its
characteristics.
Task Management
The kernel of an RTOS provides an Task management allows programmers A task object is defined by the following
abstraction layer between the to design their software as a number of set of components:
application software and hardware. separate “chunks” of codes with each • Task Control block (Task data structures
This abstraction layer comprises of six handling a distinct goal and deadline. residing in RAM and only accessible by RTOS)
main types of common services This service encompasses mechanism • Task Stack (Data defined in program residing
provided by the kernel to the in RAM and accessible by stack pointer)
such as scheduler and dispatcher that
application software • Task Routine (Program code residing in ROM)
creates and maintain task objects
Scheduling Algorithm
Scheduling Algorithm Static vs. Dynamic Scheduling Algorithm
Static vs. Dynamic Preemptive vs. Nonpreemptive
- Tasks are scheduled according to priority and Where Ci is the computation time, and Ti is the release
period
task priorities are fixed
- Computation time is known and constant
Deadline Monotonic
scheduling
The utilization will be: Priority assignment based on relative
deadlines of tasks
The theoretical limit for processes, under which we Shorter the relative deadline, higher the
can conclude that the system is schedulable is priority
Exercise :Five Periodic Tasks Least Laxity First Scheduling Algorithms in RTOS
Execution profile of five periodic tasks It assigns priority based on the slack Clock Driven Scheduling
time of a process.
Slack time is the amount of Weighted Round Robin Scheduling
time left after a job if the job was
started now.
Priority Scheduling
Its most common use is in embedded
systems, especially those with multiple (Greedy / List / Event Driven)
processors
Scheduling Algorithms in RTOS (contd) Scheduling Algorithms in RTOS (contd) Scheduling Algorithms in RTOS (contd)
Earliest Deadline First (EDF) Resource Allocation Non Blocking Critical Section
Process with earliest deadline given highest The issues with scheduling applicable here. Higher priority Thread may get blocked by
unrelated low priority thread
priority Resources can be allocated in
Weighted Round Robin Priority Ceiling
Least Slack Time First (LSF) Each resource has an assigned priority
Priority Based
slack = relative deadline – execution left Priority of thread is the highest of all priorities of
Some resources are non preemptible
the resources it’s holding
Rate Monotonic Scheduling (RMS) Example : semaphores
For periodic tasks
Priority Inheritance
Priority Inversion if priority scheduling is used The thread holding a resource inherits the priority
Tasks priority inversely proportional to it’s period of the thread blocked on that resource
Other RTOS issues Linux for Real Time Applications Interrupt Handling in Linux
Interrupt Latency should be very small Scheduling Interrupts are disabled in ISR/critical
Kernel has to respond to real time events Priority Driven Approach sections of the kernel
Interrupts should be disabled for minimum Optimize average case response time
possible time Interactive Processes Given Highest Priority No worst case bound on interrupt
For embedded applications Kernel Size should Aim to reduce response times of processes latency avaliable
be small Real Time Processes eg: Disk Drivers may disable interrupt for
Processes with high priority few hundred milliseconds
Should fit in ROM
No notion of deadlines
Sophisticated features can be removed Resource Allocation Not suitable for Real Time Applications
No Virtual Memory Interrupts may be missed
No support for handling priority inversion
No Protection
Coexistence of Real Time Applications Real Time Kernel at the lowest level Real Time Tasks
with non Real Time Ones Linux Kernel is a low priority thread Statically allocate memory
Example http server Executed only when no real time tasks No address space protection
Device Driver Base Interrupts trapped by the Real Time Non Real Time Tasks are developed in
Kernel and passed onto Linux Kernel Linux
Stability
Software emulation to hardware interrupts Communication
Interrupts are queued by RTLinux Queues
Software emulation to disable_interrupt() Shared memory
RTLinux Framework rtker – Our RTOS Pluggable Scheduler
Motivation Scheduler - part of the Application
Our own OS
Full grasp over source code – Easily modifiable, portable Kernel interacts with the scheduler
Features through an API
Modular Design Application developer needs to
Isolation of Architecture/CPU dependent and
independent code – Easy to Port implement the scheduler API
Pluggable Scheduler Can optimize on Data Structures &
Two level Interrupt Handling
Algorithms for implementing the scheduler
Small footprint
Oskit’s Device Driver Framework
Probability
Schedulability analysis must be performed
Unsafe: Safe Worst Case Hence, it is essential that an upper bound on the execution times of all tasks is
Best Case Execution Time Execution Time
Execution Time Measurement Estimate known
Exact Worst Case Commonly called the Worst-Case Execution Time (WCET)
Execution Time
Controllers in planes, cars, plants, … are expected to finish their tasks within
reliable time bounds.
Execution Time
Mapping !!!
Cont….
The set of structurally possible flows for a program, i.e. those given by the
structure of the program, is usually infinite, since e.g. loops can be taken an
arbitrary number of times
• The executions are made finite by bounding all loops with some upper limit
on the number of executions (basic finiteness)
• Adding even more information, e. g. about the input data, allows the set of Loop bounds: Easy to find in this example; in general, very
difficult to
executions to be narrowed down further, to a set of statically allowed paths. determine
This is the “optimal” outcome of the flow analysis. • Infeasible paths: Can we exclude a path, based on data
analysis?
A-B-C-E-F-G is infeasible—since if x>5, it is not possible that x *
2 < 0.
Well, really? What about integer overflows? Must be sure that
these do not
happen in the example...
Flow Info Graph
Mapping Problem exists!!!
Low-Level Analysis
Low-Level Analysis
Global Low-Level Analysis
• Considers execution time effects of machine features that reach across
entire program
Applications
RTOS
BSP
Hardware
In this architecture, all the basic OS services Apart from the above, all other basic services can
Many RTOS providers provide template
which are made part of user space are made to be made part of user space and can be run in the
form of servers.
BSP's, developer assistance, and test suites to
run as servers which are used by other
aid BSP developers in bringing up the RTOS
programs in the system through inter process QNX, Nucleus, VxWorks follows the Microkernel approach on a new hardware platform.
communication (IPC).
RTOS – KERNEL SERVICES RTOS – KERNEL SERVICES
Task Management
Task Management
During the execution of an application program,
individual tasks are continuously changing from one In RTOS each task may exist in any one of the
state to another. following states,
Dormant : Task doesn’t require computer time
However, only one task is in the running mode (i.e.
given CPU control) at any point of the execution. Ready: Task is ready to go active state, waiting
processor time
In the process where CPU control is change from
one task to another, context of the to-be-suspended Active: Task is running
task will be saved while context of the to-be-
executed task will be retrieved. This process is called Suspended: Task put on hold temporarily
context switching.
Pending: Task waiting for resource
This process of managing the heap memory is known work in units of ticks, and “absolute timers” that Enabling and disabling of an interrupt
as Heap management. work with calendar date and time. Changing and referencing of an interrupt mask
RTOS – KERNEL SERVICES RTOS – KERNEL SERVICES
Interrupt and Event Handling Device I/O Management
The interrupt and event handling mechanism of an An RTOS kernel is often equipped with a device I/O
RTOS helps to ensure: management service to provide a uniform
Data integrity by restricting interrupts from occurring framework (“API”) and supervision facility for an
when modifying a data structure embedded system to organize and access large
Minimum interrupt latencies due to disabling of numbers of diverse hardware device drivers.
interrupts when RTOS is performing critical
operations
However, most device driver APIs and supervisors
Fastest possible interrupt responses that marked the are “standard” only within a specific RTOS.
preemptive performance of an RTOS
Shortest possible interrupt completion time with
minimum overheads
RTOS vendor usually has a few license models for Development with RTOS is not a problem free
customers to choose from. process.
A perpetual license enables customers to purchase the
development set and pay an annual maintenance fee, Reliable and consistent support from supplier
which entitles he/her to upgrades and bug fixes. is a critical factor in ensuring the prompt
completion of a project.
An alternative model known as subscription model
allow customers to “rent” the development set whilst Supplier longevity thus helps to determine the
paying an annual fee to renew the access.
availability of support.
RTOS – TRADEOFFS RTOS – TRADEOFFS RTOS – TRADEOFFS
“Better” RTOS vs “better” hardware Resources vs Cost
It all starts with a product and its requirements.
What sort of device is your company building? Using a more code-efficient RTOS and To run application such-and-such, how much
application software may reduce the required memory would you need? How much memory
As you know, embedded devices run on very
hardware or allow the same functionality to be will you have available?
simple to the very complex, from mass market
achieved on less expensive Microprocessors.
consumer applications like cell phones to single-
What are the power requirements? What
shot devices like Mars landers. List of common
Or, using more expensive hardware (i.e., 32-bit response time is required?
RTOS tradeoffs are,
microprocessor vs. 8-bit) may allow a less
“Better” RTOS vs “better” hardware
expensive RTOS like Linux. That is, the Is it a “hard” real-time device, such as a military
Resources vs Cost
better/more expensive the RTOS the computer system or a medical device? Or is it a
Commercial RTOS vs in-house RTOS
worse/cheaper the hardware can be and, to some consumer device that can tolerate less true real-
Royalty Free vs. Per Device Royalty
extent, vice-versa. time performance?
In time-critical systems it is important to limit the The services chosen are those that are most likely
maximum amount of time that a process can stay going to be used in time-critical code, and did not
waiting for one of these services to complete. already have timeout capability:
REAL-TIME POSIX
POSIX.13: REAL-TIME APPLICATION
ENVIRONMENT PROFILES