5.5.15 · D4Embedded Systems & Real-Time Software

Exercises — Bare-metal vs RTOS — when to use each

1,970 words9 min readBack to topic

L1 — Recognition

Q1.1

"Real-time" means the system is fast. True or false — and give the one-word correction if false.

Recall Solution

False. Real-time means deterministic (bounded, predictable, on-time). A system that always answers in 50 ms is more real-time than one that usually takes 1 ms but sometimes 200 ms. Predictability beats raw speed.

Q1.2

Match each item to bare-metal or RTOS: (a) super-loop while(1), (b) per-task stacks, (c) mutexes and message queues, (d) "you own every timing decision".

Recall Solution
  • (a) super-loop → bare-metal
  • (b) per-task stacks → RTOS (each task needs its own stack)
  • (c) mutexes / queues → RTOS (synchronisation primitives)
  • (d) you own every timing decision → bare-metal

L2 — Application

Q2.1

A super-loop runs four jobs with WCETs ms. A sensor job (the 2 ms one) needs servicing every 5 ms. Compute the worst-case latency the sensor can suffer, and state whether the 5 ms requirement is met.

Recall Solution

Use Tool 1: ms. The sensor can wait up to 38 ms — that badly misses its 5 ms requirement (by more than 7×). The 30 ms display job is the poison.

Q2.2

Compute total utilisation for three tasks ms.

Recall Solution

Q2.3

For tasks, compute the Rate-Monotonic bound . Does the task set from Q2.2 pass?

Recall Solution

Since , the set passes the sufficient test → all deadlines guaranteed. No need to compute exact response times.


L3 — Analysis

Q3.1

System: control loop every 1 ms ( ms), Wi-Fi stack (blocking, up to 50 ms), UI redraw (up to 40 ms). (a) In a super-loop, what latency does the control loop see? (b) Under an RTOS with control at highest priority, what is its response time?

Figure — Bare-metal vs RTOS — when to use each
Recall Solution

(a) Super-loop — Tool 1: ms. Against a 1 ms deadline this misses by ~90×. Fatal. (b) RTOS, control highest priority — nothing higher exists to pre-empt it, so from the response-time recurrence the sum is empty, leaving ms. It always meets 1 ms. Wi-Fi and UI run in leftover time. See Context Switching for the cost of the pre-emption itself.

Q3.2

Two tasks, (high priority) and (low priority) ms. Use the response-time recurrence to find the low task's response time . Start at .

Recall Solution

Recurrence: . Iterate:

  • ✓ (stable)

ms. Since , the low task meets its deadline even though the high task pre-empts it twice.


L4 — Synthesis

Q4.1

A thermostat: read temp every 1 s ( ms), drive relay ( ms), refresh LCD every 0.5 s ( ms). Argue with numbers whether to choose bare-metal or RTOS.

Recall Solution

Super-loop worst case (Tool 1): ms. The tightest deadline is the LCD at 500 ms and temp at 1000 ms — both are dozens of times larger than 33 ms. No timing conflict exists. Verdict: bare-metal. An RTOS would add RAM (kernel + stacks) and context-switch overhead for zero timing benefit.

Q4.2

Add a Wi-Fi telemetry stack ( bursty, up to 200 ms, blocking) to that thermostat, plus keep the 1 ms-critical safety cutoff that must fire within 2 ms of an over-temp interrupt. Re-decide, and say how you would structure the winning design.

Recall Solution

Now super-loop latency for the safety check ms its 2 ms deadline → fails. Verdict: RTOS. Structure:

  • Safety cutoff → an ISR or highest-priority task (see Interrupts and ISRs); response sub-ms, always ms.
  • Control/relay/LCD → medium priority.
  • Wi-Fi (blocking) → lowest priority, runs in leftover time. Now the 200 ms Wi-Fi burst contributes nothing to the safety latency (only higher-priority work delays a task). Guard the whole thing with a watchdog.

L5 — Mastery

Q5.1

Four tasks in ms: . (a) Compute . (b) Compute the RM bound for . (c) Does it pass the sufficient test? (d) If a fifth task is added, recompute and the bound, and decide.

Recall Solution

(a) . (b) . (c) passes. Guaranteed schedulable under RM. (d) Add : new . New bound . Now → the sufficient test fails (inconclusive). You cannot claim safety from utilisation alone; you must run the exact response-time analysis per task, or drop/merge a task.

Q5.2 (design justification)

You are told: "Use an RTOS everywhere — it's safer." Give a numeric counter-case where bare-metal is the correct engineering choice, and name the cost the RTOS-everywhere rule ignores.

Recall Solution

Counter-case: a coin-cell sensor node with two similar-rate jobs, ms, deadlines of 1 s. Super-loop latency ms ms → trivially met. An RTOS here adds kernel flash/RAM, per-task stacks, and context-switch energy on a device whose whole budget is a battery. The ignored cost is RAM/power/certification overhead plus added non-determinism in the kernel's worst case. Bare-metal wins. Recall the mnemonic SLAP — you only reach for an RTOS when Several tasks are Latency-critical with Async I/O and differing Priorities; this node SLAPs none of those. (See also Priority Inversion and Mutexes — a whole class of RTOS-only bugs you avoid entirely by staying bare-metal.)


Recall Feynman check — say the whole page in two sentences

Bare-metal makes every job wait for the sum of all jobs, so one slow job poisons the timing of a fast critical one. An RTOS lets high-priority work pre-empt low-priority work, so a critical task waits only for higher-priority jobs — you pay RAM, power and complexity for that isolation, and you only pay it when your jobs genuinely fight over timing.

Connections