CS452 - Real-Time Programming - Spring 2010
Lecture 24 - Pathologies
Public Interest Announcements
- Demos
- How to give a demo
Pathologies
1. Deadlock
2. Livelock (Deadly Embrace)
3. Critical Races
Example
- Two tasks, A & B, at the same priority
- A is doing a lot of debugging IO
- B always reserves a section of track before A, and all is fine.
- Debugging IO is removed
- A reserves the section before B can get it, and execution
collapses.
- Lower priority of A to the same level as C.
- Now C executes more slowly, and D gets a different resource before C
.
- You shuffle priorities forever, eventually reverting to leave in the
debugging IO.
Theory of relativity and the event horizon.
Symptoms
- Small changes in priorities change execution unpredictably, and
drastically.
- Debugging output changes execution drastically.
- Changes in train speeds change execution drastically.
- Example from two terms ago
`Drastically' means chaos in both senses of the term
- Sense one: a small change in the initial conditions produces an
exponentially growing change in the system
- Sense two: exercise for the reader.
Solutions
- Knowing what order you expect things to happen
- Think a lot about pre-conditions
- Explicit synchronization
- but you then have to know the orders in which things are permitted
to occur
- Gating is a technique of global synchronization
- which can be provided by a detective/coordinator
4. Performance
The hardest problem to solve
- You just don't know what is possible
- Ask a question like:
- Is my kernel code at the limit of what is possible in terms of
performance?
- We can compare the performance on message passing, etc., because
two kernels are pretty much the same.
- Compare a lot of kernels and you should be able to find a lower
limit
- Can't do the same thing for train applications
Priority
The hardest thing to get right
- Sizing stacks used to be harder, but now we have lots of memory
- NP-hard for the human brain
- Practical method starts with all priorities the same, then adjusts
- symptoms of good priority assignment
- The higher priority, the more likely the ready queue is to be
empty
- The shorter the run time in practice the higher the priority
Problems with priority
- Priority inversion
- One resource, many clients
- Tasks try to do too much
Congestion
- Too many tasks
- blocked tasks don't count,
- lowest priority tasks almost don't count
- Layered abstraction are costly
- e.g. Notifier -> SerialServer -> InputAccumulater ->
Parser -> TrackServer
- With the hardware you have this occurs only when you start passing
around big messages.
- Access to the train controller
Hardware
- Turn on optimization, but be careful
- There are places where you have done register allocation by
hand
- Turn on caches
- Size & align calibration tables by size & alignment of cache
lines
- linker command script
- I think that this is stretching it.
Reservations
Somebody has been doing something right for the last century. The answer
is reservations.
Two Level Train Control
The two levels are completely independent of one another.
- On heavily used sections of track the lower level is done completely by
hardware with no possibility (almost) of human intervention
Upper Level
- Train asks despatcher for a route
- Despatcher provides a route that he/she thinks to be conflict free
- Train follows the route, reporting back to the despatcher as landmarks
(sensors) are passed.
- The despatcher gets two reports
- One from the hardware
- One from the engineer
- It is up to the despatcher to make certain that they do not
conflict
Lower Level
The lower level is encoded in the coloured lights you see along the
track
- Everything is rigidly enforced by hardware
- The human enters the loop only in that the lights tell the engineer
what he/she is allowed to do
- The engineer loses his licence, FOREVER, if he/she ever goes
through a red light.
- If the system ever gets something it doesn't understand, it enters a
failsafe mode
Here's how it works
- Train asks reservation system for several blocks of track
- Blocks usually end at switches and/or sensors
- If you are ending blocks at switches you must know well enough how
enough where the train is to be confident it is completely clear of
the switch.
- Reservation system grants the blocks if they are available
- Grants include the condition that the train must travel so that it
can come to a complete stop without leaving any reserved block.
In practice this works as follows.
- The reservation includes two distinct sets of blocks
- In the first set the train can travel at full speed
- In the second set the train must travel at reduced speed so that it
can stop by the end of the second set.
- Before arriving at the end of the first set, the train requests another
reservation
An Interesting Tit-bit That Doesn't Concern You
Real trains are long and sometimes occupy several blocks at once. How does
the engineer know that the end of a train is clear of a switch?
- When an engineer takes over a train he/she is given printed orders that
include the length of the train.
- There is a resetable counter in the locomotive that count the
revolutions of the locomotives wheels
- When the locomotive passes a switch the engineer resets the
counter.
Something Essential that You Must Do
Design your reservation system before coding it.
Before coding your reservation system work it out on paper and make sure
that it works for all the generic cases you can think of
- One train following another
- Two trains on a collision course
- There are one or more switches in the path
Return to: