5.5.15 · D4 · HinglishEmbedded Systems & Real-Time Software

ExercisesBare-metal vs RTOS — when to use each

2,165 words10 min read↑ Read in English

5.5.15 · D4 · Coding › Embedded Systems & Real-Time Software › Bare-metal vs RTOS — when to use each


L1 — Recognition

Q1.1

"Real-time" ka matlab hai system fast hai. Sahi hai ya galat — aur agar galat hai toh ek-word correction do.

Recall Solution

Galat. Real-time ka matlab hai deterministic (bounded, predictable, on-time). Ek system jo hamesha 50 ms mein jawaab deta hai woh zyada real-time hai uss system se jo usually 1 ms leta hai par kabhi kabhi 200 ms. Predictability raw speed se zyada important hai.

Q1.2

Har item ko bare-metal ya RTOS se match karo: (a) super-loop while(1), (b) per-task stacks, (c) mutexes aur message queues, (d) "tum khud har timing decision ke malik ho".

Recall Solution
  • (a) super-loop → bare-metal
  • (b) per-task stacks → RTOS (har task ko apna stack chahiye)
  • (c) mutexes / queues → RTOS (synchronisation primitives)
  • (d) tum khud har timing decision ke malik ho → bare-metal

L2 — Application

Q2.1

Ek super-loop mein char jobs hain jinke WCETs ms hain. Ek sensor job (woh 2 ms wala) ko har 5 ms mein service chahiye. Sensor ko jo worst-case latency ho sakti hai woh calculate karo, aur batao ki 5 ms requirement meet hoti hai ya nahi.

Recall Solution

Tool 1 use karo: ms. Sensor ko 38 ms tak wait karna pad sakta hai — yeh iske 5 ms requirement ko buri tarah se miss karta hai (7× se zyada). 30 ms display job zeher hai.

Q2.2

Teen tasks ke liye total utilisation compute karo ms.

Recall Solution

Q2.3

tasks ke liye Rate-Monotonic bound compute karo. Kya Q2.2 ka task set pass karta hai?

Recall Solution

Kyunki hai, set sufficient test pass kar leta hai → saare deadlines guaranteed hain. Exact response times calculate karne ki zaroorat nahi.


L3 — Analysis

Q3.1

System: control loop har 1 ms ( ms), Wi-Fi stack (blocking, up to 50 ms), UI redraw (up to 40 ms). (a) Super-loop mein control loop ko kitni latency milti hai? (b) Ek RTOS ke under jahan control highest priority par hai, iska response time kya hai?

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

(a) Super-loop — Tool 1: ms. 1 ms deadline ke against yeh ~90× miss karta hai. Fatal hai. (b) RTOS, control highest priority — isse pre-empt karne ke liye koi higher priority nahi hai, toh response-time recurrence mein sum empty hai, aur ms milta hai. Yeh hamesha 1 ms meet karta hai. Wi-Fi aur UI bacha hua time mein run karte hain. Pre-emption ki cost ke liye Context Switching dekho.

Q3.2

Do tasks, (high priority) aur (low priority) ms. Response-time recurrence use karke low task ka response time nikalo. se shuru karo.

Recall Solution

Recurrence: . Iterate karo:

  • ✓ (stable)

ms. Kyunki hai, low task apna deadline meet karta hai even though high task ise do baar pre-empt karta hai.


L4 — Synthesis

Q4.1

Ek thermostat: har 1 s mein temp read karo ( ms), relay drive karo ( ms), har 0.5 s mein LCD refresh karo ( ms). Numbers ke saath argue karo ki bare-metal choose karein ya RTOS.

Recall Solution

Super-loop worst case (Tool 1): ms. Sabse tight deadline LCD ki 500 ms aur temp ki 1000 ms hai — dono 33 ms se kai zyada hain. Koi timing conflict exist nahi karta. Verdict: bare-metal. RTOS yahan RAM (kernel + stacks) aur context-switch overhead add karega zero timing benefit ke liye.

Q4.2

Us thermostat mein ek Wi-Fi telemetry stack add karo ( bursty, up to 200 ms, blocking), saath hi 1 ms-critical safety cutoff raho jo over-temp interrupt ke 2 ms ke andar fire hona chahiye. Dobara decide karo, aur batao ki winning design ko kaise structure karoge.

Recall Solution

Ab super-loop latency safety check ke liye ms iske 2 ms deadline → fail. Verdict: RTOS. Structure:

  • Safety cutoff → ek ISR ya highest-priority task (dekho Interrupts and ISRs); response sub-ms, hamesha ms.
  • Control/relay/LCD → medium priority.
  • Wi-Fi (blocking) → lowest priority, bacha hua time mein run karta hai. Ab 200 ms Wi-Fi burst safety latency mein kuch contribute nahi karta (sirf higher-priority work ek task ko delay karta hai). Poori cheez ko ek watchdog se guard karo.

L5 — Mastery

Q5.1

Chaar tasks ms mein: . (a) compute karo. (b) ke liye RM bound compute karo. (c) Kya yeh sufficient test pass karta hai? (d) Agar paanchwa task add ho jaaye, aur bound dobara compute karo aur decide karo.

Recall Solution

(a) . (b) . (c) passes. RM ke under guaranteed schedulable hai. (d) add karo: naya . Naya bound . Ab → sufficient test fail ho gaya (inconclusive). Sirf utilisation se safety claim nahi kar sakte; tumhe har task ke liye exact response-time analysis run karni hogi, ya koi task drop/merge karna hoga.

Q5.2 (design justification)

Tumhe bola gaya: "Har jagah RTOS use karo — yeh safer hai." Ek numeric counter-case do jahan bare-metal sahi engineering choice hai, aur woh cost batao jo RTOS-everywhere rule ignore karta hai.

Recall Solution

Counter-case: ek coin-cell sensor node jisme do similar-rate jobs hain, ms, deadlines of 1 s. Super-loop latency ms ms → trivially met. RTOS yahan kernel flash/RAM, per-task stacks, aur context-switch energy add karega ek aisi device par jinका poora budget ek battery hai. Jo cost ignore ki ja rahi hai woh hai RAM/power/certification overhead aur kernel ke worst case mein added non-determinism. Bare-metal wins. Mnemonic SLAP yaad karo — RTOS tabhi lo jab Several tasks Latency-critical hon with Async I/O aur differing Priorities; yeh node SLAP ka koi criteria meet nahi karta. (Dekho bhi Priority Inversion and Mutexes — RTOS-only bugs ki ek poori class jisse tum bare-metal par rehkar bilkul bachte ho.)


Recall Feynman check — poora page do sentences mein bolo

Bare-metal mein har job saari jobs ke sum ka intezaar karti hai, isliye ek slow job ek fast critical job ki timing kharaab kar deta hai. Ek RTOS high-priority work ko low-priority work ko pre-empt karne deta hai, isliye ek critical task sirf higher-priority jobs ka intezaar karta hai — tum RAM, power aur complexity us isolation ke liye pay karte ho, aur sirf tabhi pay karte ho jab tumhare jobs genuinely timing ke liye ladte hain.

Connections