Worked examples — Bare-metal vs RTOS — when to use each
5.5.15 · D3· Coding › Embedded Systems & Real-Time Software › Bare-metal vs RTOS — when to use each
Shuru karne se pehle, neeche use hone wala har symbol samjha hua hai. Agar koi symbol anjaana lage, toh yahan plain-words dictionary hai — is page mein koi bhi symbol is list ke bahar nahi hai.
Scenario matrix
Is topic ka har scheduling problem inn case classes mein se ek hai. Har row ek "cell" hai jise tumhe handle karna aana chahiye. Right column us worked example ka naam batata hai jo use cover karta hai.
| # | Case class | Kya special hai | Covered by |
|---|---|---|---|
| A | Super-loop, sab fit ho jaata hai | har deadline → bare-metal jeet | Ex 1 |
| B | Super-loop, ek slow job tod deti hai | Fast critical job deadline miss karti hai → RTOS chahiye | Ex 2 |
| C | RM utilisation test PASS | → guaranteed schedulable | Ex 3 |
| D | Utilisation bound aur 1 ke beech | Test fail karta hai lekin system theek bhi ho sakta hai → exact RTA chahiye | Ex 4 |
| E | Full response-time iteration | Recurrence step by step converge hoti dikhao | Ex 5 |
| F | Degenerate: / single task | Zero-work ya one-job limits | Ex 6 |
| G | Limiting case: aur | Bound ; "100% full" ka matlab kya hai | Ex 7 |
| H | Equal periods (tie-break) | Do tasks ka period ek hi → pehle kaun jaata hai? | Ex 8 |
| I | Real-world word problem | Ek English brief ko mein translate karo aur decide karo | Ex 9 |
| J | Exam twist: overload / | Provably impossible — load shed karna padega | Ex 10 |
Example 1 — Cell A: super-loop, sab fit ho jaata hai
- Worst-case loop latency compute karo. Yeh step kyun? Super-loop mein har job, loop mein ek baar har doosri job ka wait karti hai, isliye killer number hai.
- Tightest deadline se compare karo. Yeh step kyun? Ek design tabhi safe hai jab worst wait, shortest deadline se chhoti ho. Yahan tightest deadline pressure job ka period hai, ms.
- Decide karo. Yeh step kyun? Agar loop pehle se har deadline 12× slack ke saath meet kar rahi hai, toh RTOS sirf RAM aur complexity badhayega bina kisi timing benefit ke.
Example 2 — Cell B: ek slow job loop tod deti hai
- Control loop ke liye super-loop latency. Yeh step kyun? Ek loop mein control job ko SD write ke peeche ek baar wait karna padta hai.
- Deadline se compare karo. Yeh step kyun? Control ki deadline ms hai.
- Pre-emption se fix karo. Yeh step kyun? RTOS ke under control task ko highest priority do. Uska response time (vocabulary mein define hai — ready se finish hone tak ka time, interruptions sahit) ab koi higher-priority interrupter nahi rakhta, isliye aur summation khaali hai:
Example 3 — Cell C: RM utilisation test pass ho jaata hai
- Total utilisation. Yeh step kyun? CPU ki demanded fraction hai; yeh try karne ke liye sabse sasta test hai.
- ke liye Liu & Layland bound. Yeh step kyun? Rate-Monotonic deadlines guarantee karta hai agar , se neeche ho — yeh ek sufficient (pass hone par safe) test hai. Dekho Rate-Monotonic Scheduling.
- Compare karo. Yeh step kyun? Agar bound, toh hum khatam hain — mushkil response-time analysis ki zaroorat nahi.
Example 4 — Cell D: utilisation bound aur 1 ke beech
- Utilisation. Yeh step kyun? Pehle sasta test try karo, .
- Bound. Yeh step kyun? ke liye se compare karo. Utilisation bound aur full loading ke beech mein hai — sach mein grey zone.
- Exact response-time analysis par fall back karo. Yeh step kyun? Failed utilisation test ka matlab hai "pata nahi", "unschedulable" nahi. Sabse low-priority task par recurrence chalao (task 3, , aur se pre-empt hoti hai):
- Deadline check karo. Yeh step kyun? → task 3 apni deadline meet karti hai, failed utilisation test ke bawajood.
Example 5 — Cell E: full response-time iteration
Parent note se recurrence, iteration se solve hoti hai: se shuru karo, right-hand side mein daal ke pao, jab tak value band na ho dohraate raho. Neeche ki figure dikhati hai ki yeh kyun steps mein badhti hai aur phir lock ho jaati hai.

- Start karo. Yeh step kyun? Recurrence ko ek seed chahiye; sabse chhota possible answer task ka apna kaam hai bina kisi interruption ke.
- Ek baar iterate karo. Yeh step kyun? ms ki window mein, har higher task kitni baar pre-empt kar sakti hai? arrival task 1 ki, task 2 ki.
- Dobara iterate karo. Yeh step kyun? Window 5 tak badh gayi, toh arrivals recount karo: , .
- Phir iterate karo. Yeh step kyun? Window ab 6 hai, recount: , .
- Ruko. Yeh step kyun? — value badalni band ho gayi, toh humein fixed point mil gaya.
Example 6 — Cell F: degenerate inputs (, single task)
- (a) Zero-work utilisation. Yeh step kyun? . Yeh koi CPU demand nahi karta, kisi mein kuch nahi jodta, aur uska ceiling term hai. Toh yeh har deadline ke liye invisible hai.
- (b) Single-task utilisation. Yeh step kyun? .
- Compare karo. Yeh step kyun? ke liye bound bilkul hai — ek single task CPU ka 100% tak use kar sakti hai aur phir bhi trivially schedulable hai (koi use pre-empt nahi karta).
Example 7 — Cell G: limiting case
RM bound tasks badhne ke saath chhota hota jaata hai. Figure dikhati hai yeh ki taraf slide karta hua.

- Tabulate karo. Yeh step kyun? ko mein daalo.
- Trend interpret karo. Yeh step kyun? Zyada tasks matlab unke periods align hona mushkil hai, isliye guaranteed-safe ceiling girti hai. Tum is simple rule se ~69.3% se zyada loading kabhi guarantee nahi kar sakte.
- Practical reading. Yeh step kyun? Agar tumhara design ko se neeche rakhe, toh yeh RM-schedulable hai chahe kitne bhi tasks hon. Yeh safe engineering budget hai.
Example 8 — Cell H: equal periods (ek tie)
- Tie arbitrarily break karo. Yeh step kyun? RM sirf period se ordering mandate karta hai; tie par koi bhi consistent choice legal hai. Ordering 1 try karo: A higher priority hai.
- Ordering 1 ke under lower task (B) ka response time. Yeh step kyun? B, A se pre-empt hoti hai; B ki window mein exactly ek A arrival hoti hai (dono period share karte hain). Higher task apna time rakhti hai: . Dono . ✓
- Tie swap karo — ordering 2: B higher priority. Yeh step kyun? Yeh prove karne ke liye ki choice schedulability decide nahi karti, doosri taraf se karo. Ab A lower task hai, B se ek baar pre-empt hoti hai: Aur . Dono . ✓
Example 9 — Cell I: real-world word problem
- English ko ms mein translate karo. Yeh step kyun? Har sentence ko numbers mein badlo taaki formulas apply ho sakein. IMU , PID , telemetry , SD .
- Pehle super-loop test. Yeh step kyun? Bare-metal rule in ya out karne ka sabse sasta tarika. IMU ki worst wait poora loop hai: Bare-metal fatal hai — 25 ms SD write 2 ms IMU ko starve kar deta hai.
- RTOS utilisation test. Yeh step kyun? Check karo ki RTOS workload hold bhi kar sakta hai, .
- Bound se compare karo aur exact RTA se finish karo. Yeh step kyun? ke liye: . Yahan → utilisation test inconclusive, toh flight-critical tasks par exact response-time analysis chalao. Do 2 ms tasks ko top priorities do: IMU highest (, uske upar kuch nahi), PID next (sirf IMU se ek baar 2 ms window mein interrupt: ). Dono safely 2 ms ke under hain; SD/telemetry ko best-effort background treat karo.
Example 10 — Cell J: exam twist — provable overload
- Total utilisation compute karo. Yeh step kyun? ek necessary condition failure hai — agar tasks 100% CPU se zyada demand karten, toh koi bhi scheduler madad nahi kar sakta. Yeh test RM bound ko killer ke roop mein beat karta hai.
- Interpret karo. Yeh step kyun? matlab workload ek CPU ka 160% maang raha hai. Deadlines zaroor miss hongi.
- Fix prescribe karo. Yeh step kyun? Overloaded system ke sirf teen ilaaj hain: kam karo (faster code / Worst-Case Execution Time (WCET) cuts), badhao (jobs kam baar chalao), ya hardware add karo (ek doosra core). Ek watchdog safety net hai agar overload kabhi slip through ho jaaye.
Recall Quick self-check (click to reveal)
Inme se har ek kaun sa cell hai — "super-loop 16 ms vs 200 ms deadline"? ::: Cell A (sab fit → bare-metal). , bound — pass ya fail? ::: Pass (Cell C, guaranteed schedulable). Failed utilisation test matlab unschedulable — sach ya jhooth? ::: Jhooth — yeh inconclusive hai; exact RTA chalao (Cell D). kya prove karta hai? ::: Ek CPU par kisi bhi algorithm se provably unschedulable (Cell J). RM bound ki value jab ? ::: (Cell G). wala task doosron ko kaise affect karta hai? ::: Bilkul nahi — zero utilisation, zero response-time contribution (Cell F).
Connections
- 5.5.15 Bare-metal vs RTOS — when to use each (Hinglish) — parent topic
- Rate-Monotonic Scheduling — jahaan se utilisation bound aur priority ordering aata hai
- Worst-Case Execution Time (WCET) — is page ka har ek WCET hai
- Priority Inversion and Mutexes — woh hidden delay term jo is page ki ideal RTA ignore karti hai
- Context Switching — real cost jo har baar higher task pre-empt karne par add hota hai
- Watchdog Timers — tumhara safety net jab Example 10 ka overload slip through ho jaaye
- Interrupts and ISRs — bare-metal scheduler ke bina pre-emption kaise fake karta hai