Chapter 1
Chapter 1
General Purpose Operating System
Background: What’s a “Real Time” System?
What makes an OS Real-Time?
Fire alarm system: an example
Central server
Designing an RTOS: End Goal
Priority inversion
High-level task stalled due to low-level using
shared resources, then a medium-level task
holding up the low-level one
Solution: Priority inheritance – give low-level
task high-level priority
Designing an RTOS: Common Problems
(con’t)
Deadlock
Two semaphores locked out of order by two tasks
and circularly block each other
Solution: “Instant Inheritance” implementation of
Priority Ceiling Protocol – semaphores possibly
needed by higher processes become priority tokens
Designing with an RTOS: What do you
need?
Task information
Priorities for each task
Worst-case runtime
Best-case period
Solving Problems
Logs
Time Machines
Memory Conservation
Types of RTOS
Hard Real-Time system
Hard and Soft Real Time Systems
(Operational Definition)
Hard Real Time System
Validation by provably correct procedures or extensive
simulation that the system always meets the timings
constraints
Soft Real Time System
Demonstration of jobs meeting some statistical
constraints suffices.
Example – Multimedia System
25 frames per second on an average
Role of an OS in Real Time Systems
Standalone Applications
Often no OS involved
Micro controller based Embedded Systems
Some Real Time Applications are huge &
complex
Multiple threads
Complicated Synchronization Requirements
Filesystem / Network / Windowing support
OS primitives reduce the software design time
Basic functions of RTOS kernel
Task Management
Task States
Interrupt handling
Interrupt handling
Memory management
Exception handling
Exception handling
Task Synchronization
Task Synchronization
Task scheduling
Task scheduling
Task scheduling
Task scheduling
Task scheduling
Example of Task scheduling (RR
Time management
parameters
Resource Allocation in RTOS
Resource Allocation
The issues with scheduling applicable here.
Resources can be allocated in
Round Robin
Priority Based
Some resources are non preemptible
Example : semaphores
Priority Inversion if priority scheduling is used
Priority Inversion
Solutions to Priority Inversion
Non Blocking Critical Section
Higher priority Thread may get blocked by unrelated
low priority thread
Priority Ceiling
Each resource has an assigned priority
Priority of thread is the highest of all priorities of the
resources it’s holding
Priority Inheritance
The thread holding a resource inherits the priority of the
thread blocked on that resource
Other RTOS issues
Interrupt Latency should be very small
Kernel has to respond to real time events
Interrupts should be disabled for minimum possible
time
For embedded applications Kernel Size should be
small
Should fit in ROM
Sophisticated features can be removed
No Virtual Memory
No Protection
Existing RTOS categories
RT Linux: an example
RT-Linux is an operating system, in which a
small real-time kernel co-exists with standard
Linux kernel
RT Linux Kernel
Why Linux
Footprint
Small footprint (~50kb)
Oskit’s Device Driver Framework
Allows direct porting of existing drivers from
Linux.
Example – Ethernet Driver of Linux
Other RTOS’s
LynxOS
Microkernel Architecture
Kernel provides scheduling/interrupt handling
Additional features through Kernel Plug Ins(KPIs)
TCP/IP stack , Filesystem
KPI’s are multithreaded
Memory Protection/ Demand Paging Optional
Development and Deployment on the same host
OS support for compilers/debuggers
Other RTOS’s (contd)
VxWorks
Monolithic Architecture
Real Time Posix compliant
Cross development System
pSOS
Object Oriented OS
Peripheral devices and protocols
• Interfacing
Serial/parallel ports, USB, I2C, PCMCIA, IDE
• Communication
Serial, Ethernet, Low bandwidth radio, IrDA,
802.11b based devices
• User Interface
LCD, Keyboard, Touch sensors, Sound, Digital
pads, Webcams
• Sensors
A variety of sensors using fire, temperature,
pressure, water level, seismic, sound, vision
Conclusion
Scheduling in RTOS
More information about the tasks are known
No of tasks
Resource Requirements
Release Time
Execution time
Deadlines
Being a more deterministic system better
scheduling algorithms can be devised.
Scheduling Algorithms in RTOS
Priority Scheduling
(Greedy / List / Event Driven)
Scheduling Algorithms in RTOS (contd)
Clock Driven
All parameters about jobs (release time/
execution time/deadline) known in advance.
Schedule can be computed offline or at some
regular time instances.
Minimal runtime overhead.
Not suitable for many applications.
Scheduling Algorithms in RTOS (contd)
Weighted Round Robin
Jobs scheduled in FIFO manner
Time quantum given to jobs is proportional to it’s
weight
Example use : High speed switching network
QOS guarantee.
Not suitable for precedence constrained jobs.
Job A can run only after Job B. No point in giving time
quantum to Job B before Job A.
Scheduling Algorithms in RTOS (contd)
Priority Scheduling
(Greedy/List/Event Driven)
Processor never left idle when there are ready
tasks
Processor allocated to processes according to
priorities
Priorities
static - at design time
Dynamic - at runtime
Priority Scheduling