CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 4 of 7 · 2 min read

Real time

In plain words: A fire alarm that sounds an hour after the fire is useless, though it works perfectly. In some systems, a correct result that arrives late is a failure. These are real-time systems: the correctness of a result depends on the time at which it is produced, as well as on its value. The analogy stops in one place: a late alarm is merely useless, but a late reaction in a braking system is dangerous.

Two kinds exist. In a hard real-time system, missing a deadline is a failure with serious consequences: aircraft control, brakes, pacemakers. In a soft real-time system, missing a deadline lowers quality but is tolerable: video playback that drops a frame, or an audio stream that clicks.

A common model is the periodic task: a task that becomes ready every T time units (its period) and needs C units of processor time (its computation time) before the next period begins, which is its deadline. The utilisation of one task is C ÷ T, and the total utilisation of a set is the sum. If the total exceeds 1 for one processor, no scheduler can meet all the deadlines, since the work asked for exceeds the time available.

Two policies are standard. Rate-monotonic scheduling gives fixed priorities, higher for shorter periods. Earliest deadline first (section 5) uses changing priorities. Linux offers real-time scheduling classes, covered on page 7.

Hard and soft real-time

A hard real-time system must complete every task by its deadline, because a late result is a failure; a soft real-time system treats a late result as a loss of quality, but still tolerates it.

Example: an engine controller that misses a deadline by 2 ms is a hard real-time failure, and a video player that shows a frame 2 ms late is a soft real-time case.

Check yourself: 1. Compute the utilisation of a task with a 3 ms computation every 12 ms. 2. Why can no scheduler help if the total utilisation is 1.2? 3. Is a music player hard or soft real-time?