Académique Documents
Professionnel Documents
Culture Documents
A system that maintains a continuous and timely interaction with its environment
Cruise-Control System
Brake Accelerator Wheel Rotation Desired Speed Commands
Real-Time Systems
Throttle Value
University of Pittsburgh
Manas Saksena
University of Pittsburgh
Manas Saksena
Real-Time Systems
Real-time computer system
corrects depends on when the results are produced (timeliness) in addition to what results are produced
Timing Constraints
Speed Control
sample sensor value (speed) every 100 ms, periodic activity inter-arrival time (period) output actuator command within 60 ms deadline for each arrival
Embedded System
The computer system is part of a larger system Examples: automobile control system(s) air-traffic control
Manas Saksena 3
Brake Press
University of Pittsburgh
University of Pittsburgh
Value Functions
Most real systems have a mix of hard and soft real -time components The distinction between hard and soft real -time is somewhat subjective Soft real-time is not non real-time
deadline
University of Pittsburgh
Manas Saksena
University of Pittsburgh
Manas Saksena
University of Pittsburgh
Manas Saksena
University of Pittsburgh
Manas Saksena
Controller
Reference input
A/D A/D
Control-raw computation
D/A
sensor
Plant
actuator
University of Pittsburgh
Manas Saksena
University of Pittsburgh
Manas Saksena
10
State Machines
initial state
Initialize Object
initialization
manual trigger
cruise/startControl()
automatic
shutdown/
Terminate Object
timeout/doControl()
transition
University of Pittsburgh Manas Saksena 11 University of Pittsburgh Manas Saksena 12
Schedulability Analysis
Are my timing requirements being met? Real-Time System Model
manual
automatic
A set of events Maximum arrival rate for each event A handler for each event Maximum execution time for each handler A deadline for each event Finish time (e) Arrival time (e) <= Deadline
Response Time
University of Pittsburgh
Manas Saksena
13
University of Pittsburgh
Manas Saksena
14
Concurrency
Timed Events
Timeliness of Response
Different events have different requirements How to structure software to satisfy all the requirements
Manas Saksena 16
University of Pittsburgh
Development host Compiler, debugger, loader, simulator, shell monitor NT OS (Solaris) Pentium PC station SUN workstation
Iterative process
PC Host + development tools RS-232 (console) application tasks RTOS (vxWorks) Target (MBX860)
Hardware
RS-232 Ethernet
University of Pittsburgh
Manas Saksena
17
University of Pittsburgh
Manas Saksena
18
Multi-Tasking kernel
Fixed priority, preemptive scheduling Semaphores, Message Queues, etc. Priority Inheritance
Manas Saksena
University of Pittsburgh
Manas Saksena
19
University of Pittsburgh
Manas Saksena
20
Real-time OS
G Functions: &
task management, scheduling, dispatcher communication (pipe, queue) synchronization (semaphore, event)
Schedulable Entities
Tasks Thread of Control Event Queue
Application Kernel
External interrupt
Interrupt dispatch
Timer interrupt
Scheduler
Task Queue
Signal Queue
There are many other real-time operating systems. Many developers roll out their own real-time operating system
University of Pittsburgh
Manas Saksena
23
University of Pittsburgh
Scheduling
Tasks
Primary scheduling entities Scheduled by the kernel Done within the task Usually makes sense with event-driven tasks
Events or Messages
Signals
Interrupts to tasks Useful for activating tasks (e.g., timer expiry)
Events are primary units for scheduling Application = Set of Events and their Responses
Single Task or Multiple Tasks
University of Pittsburgh
Manas Saksena
25
University of Pittsburgh
Manas Saksena
26
Non-Preemptive
Wait for Event Process Event Priority Based Event Priorities
Task Priorities
Application Controlled
Application Controlled
Terminate
Terminate
Manas Saksena
Manas Saksena
30
Interrupts Timers
Implementing Tasks
Two Common Ways
Interrupt Handlers Threads Need an RTOS that supports threads (also called tasks in many RTOSes)
Event Handlers
Interrupt Handlers
fast response times difficult to program correctly often IH will do some minimal work and then wake up a task to the real work
Manas Saksena 32
University of Pittsburgh
Manas Saksena
31
University of Pittsburgh
Multi-Tasking
Communications
Key Concepts
Tasks
Encapsulate thread of control Schedulable Unit Each task implements one function
Scheduling
Priorities IH may be viewed as higher priority tasks Preemptive Priority Scheduling kernel is usually fully preemptive
University of Pittsburgh Manas Saksena 33
Protected Objects
Encapsulate Shared Data (Resource) Mutually exclusive operation of Object Methods
University of Pittsburgh
Manas Saksena
34
Preemption
Execution delayed by higher priority tasks Execution delayed by lower priority tasks
priority
time
University of Pittsburgh Manas Saksena 35 University of Pittsburgh Manas Saksena 36
Preemption Analysis
Each higher priority task has a preemption effect Depends on Number of Arrivals and Execution Time of the Higher Priority Task
I j ( R ) = NumArrival s j ( R ) C j
Number of Arrivals of Task j in a window of interval R Preemption Effect from Task j
University of Pittsburgh
S1
low
High and low priority tasks share a resource This can lead to UNBOUNDED Blocking
s1
highest
Attempts to lock S1
high medium s1 s1 s1
low
Response Time
Manas Saksena 37
Normal execution
s1
S1
low
High and low priority tasks share a critical section Ceiling Priority of CS = Highest Priority Task that can use the CS Execute CS at Ceiling priority
Ready s1 Ready
S1
low
High and low priority tasks share a critical section Inherit priority of blocked task in critical section
highest
high medium s1 s1 s1
highest
Attempts to lock S1
s1
low
low
Normal execution
University of Pittsburgh
Normal execution
University of Pittsburgh
s1
Manas Saksena
Manas Saksena
Blocking Analysis
Common Property
A lower priority task can cause blocking only while it is in a critical section
S1 S2
Same task set as sample problem Assumes priority inheritance used May need to wait for all possible critical sections
Attempts to lock S2 S1 S2
Attempts to lock S1
1
S1 S1
Highest Locker
The critical section must have a ceiling priority that is higher (or equal) than task priority Only one such CS can cause blocking
2
S2
S2
Multiple CS can cause blocking in a chained manner The effect is sum of the largest such chain
University of Pittsburgh Manas Saksena 42
Normal execution
S1 S2
University of Pittsburgh
Manas Saksena
Design/Implementation Choices
Non-Preemptive Scheduling
Similar Analysis, but consider that No preemption effect once task is given CPU Blocking effect due to non-preemptive execution
jhp ( i )
I j ( Ri )
Priority Assignment
Preemption and Blocking Effects Depend on Task Priorities
Ri Ti
) Task Response times depend on all these three factors. ) These represent design/implementation choices.
43 University of Pittsburgh Manas Saksena
University of Pittsburgh
Manas Saksena
Why Linux?
Linux as a Real-Time Operating System
Reliable, Full-featured Operating System Rich multi-tasking support Security, Protection
Networking Support TCP/IP, RSVP, SIP, MPLS, H.323 Multimedia Support JPEG, MPEG, GSM Unix Lineage Familiar environment for many users/developers POSIX Compliance
Manas Saksena
University of Pittsburgh
Manas Saksena
45
University of Pittsburgh
Manas Saksena
46
Why Linux?
The Cost Factor
Free run-time royalties A global team of programmers enhancing the environment literally all the time Availability of libraries, tools, and device drivers Source Code Access allowing peeking inside the hood (and customizing as necessary)
Why Linux?
Small Embedded Systems
Modular Kernel, possible to configure the kernel to suitable size Customizable Root File System BusyBox Utilities
University of Pittsburgh
Manas Saksena
48
Encapsulates a thread of control and an address space Address space may be shared giving threads in effect Schedulable Entity
Threads
Are processes to the Linux kernel Scheduled by the Linux kernel Can be created such that they share the address space with the parent process, effectively giving threads
University of Pittsburgh Manas Saksena 49
POSIX 1003.1.c (Thread Extensions) Using pthreads library Thread creation, destruction, etc.
Mutexes, Condition Variables
Networking:
BSD Sockets
University of Pittsburgh Manas Saksena 50
Modules
ipc
net
Device Drivers
Core Mechanisms
University of Pittsburgh
Manas Saksena
51
University of Pittsburgh
Many real-time tasks are driven by timer interrupts In Standard Linux, the timer is set to expire at 10 ms intervals
A process running in the kernel cannot be preempted by another (higher) priority process Introduces, unwanted priority inversion
Scheduler Predictability
Linux scheduler keeps tasks in an unsorted list Requires a scan of all tasks to make a scheduling decision Scales poorly as number of tasks increases, and is especially poor for real-time performance
Resource Sharing
University of Pittsburgh
Manas Saksena
53
University of Pittsburgh
How to leverage the advantages of Linux, while making it suitable for real-time systems?
TimeSys Linux/RT, Hard Hat Linux Resource Kernel Approach TimeSys Linux/RT
University of Pittsburgh
Manas Saksena
55
University of Pittsburgh
Manas Saksena
56
University of Pittsburgh
Manas Saksena
57
University of Pittsburgh
Manas Saksena
58
Linux is defined by its API and not by its internal implementation The real-time kernel is a non Linux kernel
Compliance
100% Linux API
Support all of Linux kernel API Any Linux application can run on real -time kernel Development can be done on Linux Host, with rich set of host tools for development All Linux libraries are trivially available to run on real-time kernel Third party software Achieving 100% Linux API is non-trivial Consider the amount of effort put on Linux kernel development
59 University of Pittsburgh Manas Saksena 60
Implications
Implications
No benefits from the Linux kernel Not possible to benefit from the Linux kernel evolution Not possible to use Linux hardware support Not possible to use Linux device drivers
University of Pittsburgh Manas Saksena
10
Kernel-Level
Real-Time Task
Real-Time Task
Real-Time Task
Linux Kernel
Hardware
University of Pittsburgh
Manas Saksena
61
University of Pittsburgh
Manas Saksena
62
Linux Preemptability
Linux kernel is run as the lowest priority task in the real-time kernel
Programming Model
Real-Time Tasks Non Real-Time Tasks
Linux kernel can be preempted at any time by the real-time kernel Real-Time kernel is a small multi -tasking kernel providing multi-tasking, inter-task communication and synchronization, and a fixed priority scheduler
Very tight response times for rt-tasks
University of Pittsburgh Manas Saksena 63
Real-Time Tasks
Run in kernel Limited API, restricted to what is provided by the real-time kernel
Programming Model
Memory Protection
Not available for real-time tasks A single errant real-time task can bring the system down
Duplication of Functionality
Currently: Multi-tasking, task scheduling, inter-task communication and synchronization Future Extensibility E.g., IP protocol stack, file system,
Consider Real-time often involves many shades of gray (soft real -time)
The soft/hardness of real-time may be dynamically decided
Implications
Support soft real-time tasks in real-time kernel Limited API Support soft real-time tasks in Linux kernel No performance guarantees
11
Mechanisms
Static Configuration Can be configured at compile time Dynamic Configuration Using loadable kernel modules
Manas Saksena 68
University of Pittsburgh
Manas Saksena
67
University of Pittsburgh
Preemptive Kernel
Linux kernel is non-preemptive
Simplifies synchronization in the kernel since kernel data structures that are not touched by interrupts need not be locked. Introduces potentially large priority inversions
Solution Use schedulable entities (interrupt threads) to do the bulk of the work These can be prioritized according to application requirements
University of Pittsburgh Manas Saksena 70
Priority Inheritance
A lower priority process holds a resource needed by a higher priority process
Can lead to unbounded priority inversion, unless some form of priority inheritance is used. Solution Provide a kernel mutex implementation that supports priority inheritance Use the mutex for locks in the kernel Export the mutex to user level processes using system calls
Solution Use a one-shot hardware timer to support all software timers Use a 10 ms periodic timer to do regular Linux timer work Can provide high accuracy at a low overhead
71 University of Pittsburgh Manas Saksena 72
University of Pittsburgh
Manas Saksena
12
Predictable Scheduler
Current Linux Scheduler
Need to avoid primitives that can take extended time in the kernel
Real-Time Scheduler
Predictable, Low Overhead Separate real-time and non real-time Non real-time processes do not effect real-time scheduling behavior Implement a better scheduler
University of Pittsburgh Manas Saksena 73
Solution(s)
Allows the use of most existing device drivers written to support Linux.
Need to avoid poorly written drivers that unfairly hog system resources
University of Pittsburgh
URLs
www.embedded.com
http://cs-www.bu.edu/pub/ieee-rts/Home.html
University of Pittsburgh
Manas Saksena
75
13