Section 6.34

Real-time system

Definition

A real-time system is a computing system whose correctness depends on when a result takes effect as well as on what the result is. Each piece of work must finish by a deadline: the latest time at which its result is still acceptable. Requirements are classed by the cost of a miss: hard when a miss can cause failure or harm, firm when a late result is worthless but occasional misses are tolerated, and soft when a late result keeps some value. Real-time means predictable, not fast.

The idea

An airbag controller decides correctly to fire the airbag, but the decision arrives after the occupant has already struck the steering wheel. The computation was right and the system failed. A video player that decodes a frame too late to show it drops the frame, and the picture stutters. A weather display that updates a little late harms nobody. The same lateness is a catastrophe, a degradation or nothing, depending on what the result is for.

A real-time requirement therefore has two parts: a time limit for each piece of work, and a statement of what a miss costs. The second part decides what evidence is needed. A hard requirement needs an argument that the worst case meets the deadline, because a single miss is a failure. A soft requirement can be judged from measured distributions, because an occasional miss only lowers quality. Speed alone gives neither: a system that is fast on average can still be slow at the one moment that matters.

How it works

The vocabulary:

A real-time requirement is set up and checked in this order.

  1. Name the event that releases each job and the effect that completes it.

  2. Set the relative deadline from the physics or the service: how long after the event the effect is still useful.

  3. Classify a miss as hard, firm or soft.

  4. Bound the load: how often jobs can be released, for example a minimum time between two releases, and the WCET of each job.

  5. Show that every job meets its deadline (hard), that misses stay within the tolerated pattern (firm), or that the distribution of lateness stays within the stated bound (soft). For a hard requirement this means computing the worst-case response time: the job’s own execution time plus all the time the job can spend waiting for higher-priority work, for locks held by other threads, for interrupt handlers §6.12 and for devices. A real-time operating system (RTOS) helps here, because its priority scheduling and bounded kernel operations make that waiting time calculable.

Worked example

A task is released every 20 ms, at r=0,20,40,60,80r = 0, 20, 40, 60, 80 ms, and each job has the relative deadline D=8D = 8 ms. The five jobs finish at f=5,26,52,67,86f = 5, 26, 52, 67, 86 ms. All times are in milliseconds:

Job rr d=r+8d = r + 8 ff response f−rf - r lateness f−df - d
1 0 8 5 5 −3-3
2 20 28 26 6 −2-2
3 40 48 52 12 +4+4
4 60 68 67 7 −1-1
5 80 88 86 6 −2-2

The average response time is (5+6+12+7+6)/5=36/5=7.2(5 + 6 + 12 + 7 + 6) / 5 = 36 / 5 = 7.2 ms, below the 8 ms deadline. Yet job 3 finished at 52 ms, 52−48=452 - 48 = 4 ms after its absolute deadline. The average hides exactly the job that matters.

What the miss means depends on the task.

Stated precisely

For job ii, let rir_i be its release time, DiD_i its relative deadline, di=ri+Did_i = r_i + D_i its absolute deadline, and fif_i the time at which its required effect happens, all in the same unit. Job ii meets its deadline exactly when fi−ri≤Di,equivalentlyfi≤di.f_i - r_i \le D_i, \quad \text{equivalently} \quad f_i \le d_i. Its lateness is Li=fi−diL_i = f_i - d_i, and its tardiness, the amount by which it was late, is max(0,Li)\max(0, L_i).

The three classes are three kinds of requirement over all jobs.

The periodic task model of Liu and Layland (1973) is the classic setting for hard requirements: each task releases a job every TT time units, each job needs at most CC units of processor time, and each deadline equals the period, D=TD = T.

Limits and common mistakes

Real-time does not mean fast. A system that always answers within 100 ms meets a 100 ms hard deadline; a system that usually answers in 1 ms but occasionally takes 200 ms does not.

The largest response time seen in tests is not the worst case, because tests exercise only the paths and timings that happen to occur. A hard claim needs an analysis that covers every case the assumptions allow, and it is only as strong as those assumptions: if jobs arrive more often than assumed, or a fault outside the fault model occurs, it says nothing.

Using an RTOS does not make a system real-time. The RTOS bounds its own overheads; the application’s execution times, priorities, locks and devices decide whether deadlines are met.

The deadline must name the effect. A job that has handed a command to a queue has not yet moved the actuator, so a response time measured to the hand-off understates the true one.

A timeout §9.34 is not a deadline. A timeout says when a waiting party stops waiting; the work itself may continue, and enforcing a timeout makes no work finish on time. The entry on deadlines and timeouts treats the difference.

The class belongs to each requirement, not to the whole system. One device can have a hard deadline for a motor command, a firm one for a radio reply and a soft one for its display.

Questions answered

Is a missed deadline catastrophic, degraded, or merely inconvenient?

Whether a missed deadline is catastrophic, degrading or merely inconvenient depends on what the result is for, and each real-time requirement must state which of the three applies. A missed deadline is catastrophic in a hard real-time requirement, where a late result can cause failure or harm, such as a late brake command; no miss is acceptable, and the worst-case response time must be shown to fit the deadline. It degrades the service in a firm real-time requirement, where a late result is worthless and discarded but occasional misses are tolerable, such as a video frame that arrives too late to show; the requirement bounds how many misses may occur, for example at most one in any five consecutive jobs. It is merely inconvenient in a soft real-time requirement, where a late result still has some value, such as a slow display update; the requirement bounds a statistic of lateness, such as the 99th percentile of the response time.

The application decides the class, not the operating system and not the average speed. The class in turn decides the evidence needed: a worst-case argument for hard, a bound on the pattern of misses for firm, and a measured distribution for soft.

Related entries: Deadline versus timeout (§9.34), Schedulability (§9.37), Worst-case execution time (WCET) (§9.33), Response time versus execution time (§9.32), Fixed-priority response-time analysis (§19.4.7), Zephyr RTOS (§6.33). Further reading: [86].