Title: Embedded Systems Introduction to Real-Time Systems
1Embedded Systems Introduction to Real-Time
Systems
2Real-Time Systems
Definition Real-time systems are those in which
the correctness of the system depends not only on
the logical results of the computation but also
on the time at which the results are
produced. Hard real-time systems time critical
- it is imperative that the system respond within
a specified time period. Soft real-time systems
the system will function correctly, although at a
lower overall utility if deadline are
occasionally missed.
3Real-Time Systems
timing constraints periodic --- once per period
T, precisely T units apart aperiodic --- start
time, finish time, or both
4Real-Time Programming
- Concurrent, task-based approach
- multi-tasking RTOS (VxWorks)
- scheduling theory
- industrial state-of-the-art
- Synchronous approach
- reactive kernel represented as an automata
- formal properties
- special-purpose programming languages - Esterel
- Discrete-Event Dynamic Systems
5Logical Concurrency
- A concurrent program can be viewed as a
collection of autonomous sequential processes
executing (logically) in parallel. Each process
has a single thread of control. - multiplex on a single processor
- multiplex on a multi-processor with shared
memory or - multiplex on several processors without share
memory (distributed systems)
6Processes
A process (task) can be in one of the following
process states Ready Processes that are ready
to execute. Stored in a ReadyQueue (a linked
list) Running The currently executing process
(the first process in the ReadyQueue) Blocked
Processes waiting for an event, e.g., an
external event (Temp lt Tmin) The switch from one
running process to another is called a context
switch
- The process state consists of
- program counter,
- process status information (priority, enabled
interrupts), and - the contents of the programmable registers.
- Process administration is handled by the RT kernel
7Interactive C - Multitasking
process - a function with a unique pid, local
program stack (256 bytes default) for return
addresses, local variables, arguments, etc, and a
processor allocation in milliseconds---processes
communicate via global variables process table -
a set of processes that are logically concurrent
8HandyBoard Process Control
- int start_process(function-call(),
TICKS,STACK-SIZE) - returns the process id
- int kill_process(int pid)
- returns 0 if successfully killed, 1 otherwise
(process not found) - kill_all()
- stops all running processes
- ps
- processor status
- void hog_processor()
- allocates an additional 256 msec to the function
currently running-called repeatedly, system will
wedge requiring reset - void defer()
- Forces a context shift
9Example Multitasking
void check_sensor(int n) while(1)
printf(sensor d is d\n, n, digital(n)) voi
d main() int pid pid start_process(check_sens
or(2)) sleep(1.0) kill_process(pid)
starts check_sensor() and then kills it 1 second
later
Q how often does check_sensor() actually run?
10Example Multitasking
void check_sensor(int n) while(1)
printf(sensor d is d\n, n, digital(n)) voi
d main() int pid pid start_process(check_sens
or(2)) sleep(1.0) kill_process(pid)
starts check_sensor() and then kills it 1 second
later
Q how often does check_sensor() actually run? A
assuming nothing else is in the process table,
this process runs continuously in about 200
consecutive 5 msec chunks.
11Scheduling
...to ensure that the run-time scheduler
dispatches the runnable processes in an order
that will result in all deadlines being
met orders the ReadyQueue allocates
priorities BOTH STATIC AND DYNAMIC
PRIORITY ALLOCATIONS ARE POSSIBLE
12Scheduling
- Operations Research
- job shop scheduling and shop-flow problems
- schedule physical devices and processes -
machines, - workcells, maintenance, orders,
batches, projects - mostly (not exclusively) static schedules
- Computer Science
- schedule tasks in a uni- or multiprocessor
environment - mostly (not exclusively) dynamic schedules
13Scheduling-Problem Formulation
- Events - anything that requires a response in the
system---computation, - work, communication
- periodic, aperiodic, sporadic, and stochastic
events - interrupts
- Time - execution times for event handling---how
much time will it take to handle an event? - How much CPU time does a periodic process
require? - How much time will it take to change a bearing
on the milling machine? - Deadline
- upper bound on the time required to service an
event - Scheduling
- reflects decisions about which event to process
at a given time
14Priority-Based Preemptive Scheduling
How should processes be scheduled in order to
maximize the utilization of the system while
guaranteeing deadlines? priority reflects the
severity of the time demands high
low 0 255 The ReadyQueue is
sorted by priority A blocked process that
becomes ready and has higher priority than the
currently running process causes a context shift.
This task preempts the running task.
15Priorities and Scheduling
Priority Inversion Consider tasks T1, T2, and T3
with corresponding priorities P1gtP2gtP3 (that is,
task T1 has the highest priority). If task T1
depends on task T3, it may be suspended in order
to wait for a result from T3. However, a
priority-based preemptive scheduler will choose
to run task T2, thus further blocking task T1
indirectly by way of task T3 even though P1gtP2.
16Priorities and Scheduling
Priority Inheritance The priority of a process is
the max of its priority and the priorities of all
other processes that depend on it. therefore
task T3 inherits priority P1 while T1 is waiting
for a T3 event T3 will run in
preference to T2. For example, a synchronous
communication protocol (rendezvous) requires the
sender to wait until contact is established and
the receiver is verified before the message is
sent. In ADA, the priority of the rendezvous
itself is the highest priority of the two
participating processes.
17Schedulability
Given a single processor, a set of n-independent,
periodic processes with only execution time
deadlines (no start/stop constraints) are
schedulable if the overall processor utilization
is less than n(21/n-1) For large n this
function approaches a utilization of 0.693. This
is a very conservative estimate, based on
worst-case relationships between the periods of
the processes. Liu and Layland (1973)
18Schedulability
Given a single processor, a set of n-independent,
periodic processes with only execution time
deadlines (no start/stop constraints) are
schedulable if the overall processor utilization
is less than n(21/n-1) For large n this
function approaches a utilization of 0.693. This
is a very conservative estimate, based on
worst-case relationships between the periods of
the processes. Liu and Layland (1973)
non-repeating prime periods in n processes
19Schedulability
Consider two tasks, T1 and T2, with P1gtP2 (T1 is
more important). T1 has a period of 50 units of
time and requires 10 units of time to run. Task
T2 has a period of 10 units of time and requires
2 units of time to run. Under a
priority-based preemptive schedule, T1 will
execute first and when it completes, T2 will have
already missed its first deadline! The problem
is related to the use of preference priorities.
20Schedulability
Consider two tasks, T1 and T2, with P1gtP2 (T1 is
more important). T1 has a period of 50 units of
time and requires 10 units of time to run. Task
T2 has a period of 10 units of time and requires
2 units of time to run. Under a
priority-based preemptive schedule, T1 will
execute first and when it completes, T2 will have
already missed its first deadline! The problem
is related to the use of preference priorities.
schedulability n(21/n-1) 2(21/n-1) 0.818
21Schedulability
Consider two tasks, T1 and T2, with P1gtP2 (T1 is
more important). T1 has a period of 50 units of
time and requires 10 units of time to run. Task
T2 has a period of 10 units of time and requires
2 units of time to run. Under a
priority-based preemptive schedule, T1 will
execute first and when it completes, T2 will have
already missed its first deadline! The problem
is related to the use of preference priorities.
schedulability n(21/n-1) 2(21/n-1) 0.818
22Schedulability
Consider two tasks, T1 and T2, with P1gtP2 (T1 is
more important). T1 has a period of 50 units of
time and requires 10 units of time to run. Task
T2 has a period of 10 units of time and requires
2 units of time to run.
schedulability n(21/n-1) 2(21/n-1) 0.818
so we know its schedulable
23Rate Monotonic Scheduling
Assign fixed priorities inversely proportional to
the period for the tasks Pi 1/ri, so that the
shorter the period, the higher the priority.
optimal static schedule for independent
periodic processes if a process can be scheduled
by any static scheduling algorithm, then it can
also be scheduled by the rate monotonic algorithm.
24Extensions to Rate Monotonic Scheduling
Soft RT Systems - if all deadlines cannot be met,
the most important processes must be
run first. If the ReadyQueue is
schedulable, then the process with the shortest
period should be first. Specification
Aliases - transforming specifications for the
most important tasks. If T1 (?50, and execution
time10) were respecified e.g., T1'(?5, and
execution time1), then relative preference is
consistent with its rate-based priority. the
details are non-trivial Periodic Servers -
incorporate aperiodic, interupts, and important
soft-deadline tasks into the rate monotonic
schedule. reserve time in the periodic server to
handle worst-case arrival rates global
schedule---even for tasks with random arrival
rates! at the expense of utilization
25Other Scheduling Algorithms
Earliest Deadline - need to know about
deadlines Least Slack Time - need deadlines and
complete times when deadlines can be met, ED and
LST are equivalent to Rate Monotonic
26Other Scheduling Algorithms
Earliest Deadline --- need to know about
deadlines Least Slack Time --- needs deadlines
and the amount of execution time needed to
complete... ...scheduler allocates resources to
the task with the least free
time When all deadlines can be met, Earliest
Deadline and Least Slack Time are equivalent to
Rate Monotonic --- every periodic task load
schedulable by one is schedulable by all. These
alternatives are designed to do the best they can
with instantaneous and aperiodic task loads.
27Periodic Tasks Revisited
A feedback control process is the canonical
periodic task with a fixed period---the sampling
rate. between sampling intervals, the system
is ballistic
28Periodic Tasks Revisited
- in practice, the control delay is not
constant---variations are due to - preemptions from higher priority tasks
- variation in the execution times (branching,
data dependencies) - communication delays in distributed controllers
- jitter can result from
- preemptions from higher priority tasks
- improper useage of timing primitives in the RT
kernel