Worked examples — Structural hazards
5.2.5 · D3· Hardware › Processor Datapath & Pipelining › Structural hazards
Yeh page Structural hazards ka exhaustive worked-example companion hai. Parent note ne resource conflict ka idea build kiya tha — do pipeline stages ek hi clock tick mein same piece of hardware ke liye haath badhate hain. Yahan hum har tarah ke scenario ko dhundhte hain jo yeh idea produce kar sakta hai aur arithmetic grind karte hain, taaki exam mein koi bhi case surprise na kare.
Agar neeche koi word unfamiliar lage (stage, cycle, stall, CPI), toh parent note aur Pipelining Fundamentals unhe zero se define karte hain. Hum sirf wahi reuse karte hain.
The scenario matrix
Har structural-hazard problem jo tumhe milega, woh neeche ke cells mein se ek hoga. Ek "cell" ek class of situation hai — kaunsa resource conflict hai, numbers kaise behave karte hain, aur question actually kya test kar raha hai — in teenon ka combination.
| # | Cell (case class) | Kya ise distinct banata hai | Covered by |
|---|---|---|---|
| A | Single unified memory (IF vs MEM) | Classic 2-way port conflict, non-zero load fraction | Example 1 |
| B | Zero-hazard / degenerate input | Hazard probability → koi stall nahi | Example 2 |
| C | Every-instruction hazard (limiting value) | Conflict har cycle par, | Example 3 |
| D | Multi-cycle resource (penalty ) | Stall penalty ek cycle se bada | Example 4 |
| E | Do independent hazard sources add hue | Memory hazard aur functional-unit hazard saath mein | Example 5 |
| F | Fix-by-hardware comparison | Same program, resource add karne se pehle vs baad mein | Example 6 |
| G | Real-world word problem | Embedded chip, throughput in MIPS | Example 7 |
| H | Exam twist: "reorder to remove stall" | Arithmetic ki jagah scheduling | Example 8 |
| I | Superscalar / port-count degenerate | Ports vs ek cycle mein demanded accesses | Example 9 |
Numbers se pehle, ek master formula jo har cell use karta hai.
Example 1 — Cell A: single unified memory
Forecast: andaza lagao — kya CPI , , ya ke paas aayega? (Apna guess rokho; is example ke end mein confirm karenge.)
Neeche ki figure ek pipeline timeline hai: har row ek instruction hai, har column ek clock cycle hai, aur har rounded box dikhata hai ki woh instruction us cycle mein kaun sa stage occupy kar raha hai. Column 4 dekho — wahan collision hoti hai.

- aur identify karo. Har load/store, jab MEM mein hota hai, memory chahta hai usi tick par jab ek baad waali instruction IF chahti hai. Toh aur . Yeh step kyun? Formula ko ek hazard probability aur ek penalty chahiye — aur kuch nahi. Hume English (" loads hain") ko mein translate karna hai.
- Equation apply karo. . Yeh step kyun? Master formula mein direct substitution — ise build karne ka poora point yahi hai.
- Percentage slowdown. Throughput fraction , toh pipeline ideal speed ka rakhta hai. Percentage slowdown → slower. Yeh step kyun? Performance CPI ke inversely proportional hai; slowdown woh lost share hai, yaani throughput fraction se ek minus karo.
Forecast check: answer middle guess hai — agar tumne " ke paas" chuna tha, sahi tha.
Verify: Figure dekho — cycle 4 mein, I1 MEM (coral) mein baitha hai aur I4 IF (lavender) chahta hai: ek memory, do demands → exactly ek bubble, se match karta hai. Units: CPI cycles/instruction hai; throughput fraction aur slowdown dimensionless hain. ✓
Example 2 — Cell B: degenerate zero case
Forecast: kya saare memory instructions hataane se hazard poora khatam ho jaata hai, ya koi residual stall hamesha rehta hai? (Abhi decide karo; answer neeche aata hai.)
- set karo. Koi instruction kabhi MEM tak data memory maangne nahi pahunchi, toh IF kabhi block nahi hoti. Yeh step kyun? Yeh model ki boundary hai — hume confirm karna hai ki jab hazard ho hi nahi sakta toh formula sensibly behave karta hai.
- Formula apply karo. . Yeh step kyun? Dikhata hai ki structural-hazard term vanish ho jaata hai; pipeline ideal par wapas aa jaati hai.
Forecast check: hazard poora khatam ho jaata hai — CPI ideal par aa jaata hai zero residual stall ke saath. Agar tumne "no residual stall" predict kiya tha, sahi.
Verify: . Ek pipeline jo kabhi conflict nahi karti, uska CPI ideal hona chahiye — number hamare intuition ko confirm karta hai, toh model apni lower edge par trustworthy hai. ✓
Example 3 — Cell C: limiting value
Forecast: agar har instruction ek baar stall karti hai, toh kya CPI double ho jaata hai, ya kam badhta hai? (Guess karo, phir padho.)
- , set karo. Har instruction exactly ek bubble leta hai. Yeh step kyun? Upper extreme test karna range ko complete karta hai — kisi bhi reader ko yeh wonder nahi karna chahiye "agar hamesha ho toh kya?"
- Formula apply karo. . Yeh step kyun? Confirm karta hai ki 1-cycle penalty ka worst case doubling hai, kuch wilder nahi.
- Percentage slowdown. Throughput fraction ; slowdown → pipeline half speed par chalti hai ( slower).
Forecast check: CPI exactly double hokar — agar tumne "double" guess kiya tha, bilkul sahi.
Verify: Har instruction ke saath ek bubble, effectively do cycles per completed instruction → CPI . Half throughput. Numbers agree. ✓
Example 4 — Cell D: ek multi-cycle resource ()
Forecast: ek rare event lekin costly — kya Example 1 ke frequent-but-cheap hazard se bada ya chhota effect? (Predict karo, phir step 3 check karo.)
- aur padhlo. , (teen bubble cycles per divide). Yeh step kyun? Penalty ab nahi hai; hume blindly assume nahi karna chahiye.
- Formula apply karo. . Yeh step kyun? Dikhata hai ki product matter karta hai, na sirf koi ek factor.
- Example 1 se compare karo. Divider stall term memory stall term , toh CPI : rare-but-costly divider frequent memory clash se thoda kam hurt karta hai. Yeh step kyun? Exams mein "kaunsa hazard zyada costly hai?" yeh often poochha jaata hai — answer hamesha woh hoga jiska bada ho.
Forecast check: smaller effect — divider () memory hazard () se kam hurt karta hai. Agar tumne "smaller" guess kiya tha, sahi.
Verify: ; . Aur , toh , comparison confirm karta hai. ✓
Example 5 — Cell E: do hazards stacked
Forecast: kya CPI increases sirf add hoti hain, ya multiply hoti hain? (Ek chuno; answer step 1 mein hai.)
- Stall terms add hote hain. Total stalls per instruction . Yahan index do sources par range karta hai. Yeh step kyun? Independent bubble sources independent extra cycles contribute karte hain — bubbles count hote hain, toh sum hote hain (yahi master formula ka hai).
- Formula ek baar apply karo. . Yeh step kyun? Master formula ka doosra term saare stall sources ka sum hai.
Forecast check: woh add hoti hain (multiply nahi) — do stall terms aur sum hokar bante hain.
Verify: ; . Notice karo yeh Example 1 ka CPI () plus Example 4 ka extra () ke barabar hai — additivity holds karta hai. ✓
Example 6 — Cell F: hardware fix se pehle vs baad mein
Forecast: kya speedup exactly hai, ya kuch chhota? (Guess karo, phir step 2 dekho.)
Neeche ki figure dono designs side by side contrast karti hai: left par, ek shared memory box IF aur MEM ko fight karne deta hai; right par, do alag cache boxes har ek stage ko serve karte hain, toh kuch collide nahi karta.

- New CPI. Alag caches ke saath, IF aur MEM alag ports use karte hain → , toh . Yeh step kyun? Hardware add karna resource conflict khatam karta hai, us hazard ka zero par la deta hai.
- Speedup factor. Performance , toh speedup . Yeh step kyun? Ek hi program par do designs compare karna matlab CPI directly compare karna (clock period unchanged). Yahan speedup se zyada hai kyunki nayi machine faster hai.
Forecast check: exactly — speedup old CPI ke barabar hai kyunki new CPI hai.
Verify: faster. Figure Harvard split dikhati hai: do alag memory boxes, toh cycle 4 mein koi clash nahi. Yeh construction se Pipeline Stalls ka cure hai. ✓
Example 7 — Cell G: real-world word problem
Forecast: kya throughput 200, 160, ya 100 MIPS ke paas hoga? (Guess karo; end mein confirm hoga.)
- CPI. . Yeh step kyun? Throughput ke liye pehle cycles-per-instruction chahiye.
- MIPS = clock / (CPI ). Instructions per second . Yeh instructions per second deta hai; se divide karna "instructions per second" ko "millions of instructions per second" mein convert karta hai (yahi MIPS mein M ka matlab hai). Toh MIPS. Yeh step kyun? Hum pehle raw instructions/second nikalte hain, phir se rescale karte hain purely as a unit change taaki answer millions mein padhe.
- Ideal MIPS. CPI ke saath: MIPS. Hazard cost MIPS. Yeh step kyun? "Cost" ideal aur actual throughput ka gap hai.
Forecast check: answer 160 MIPS hai — middle option. Agar tumne "160 ke paas" guess kiya tha, sahi.
Verify: ; MIPS lost. Units: (cycles/s)/(cycles/instr) = instr/s ✓. Sanity: loss, se match karta hai. ✓
Example 8 — Cell H: exam twist (reorder karo, arithmetic nahi)
Forecast: kya clever ordering yeh dodge kar sakti hai, ya yeh fundamentally ek hardware shortage hai? (Decide karo, phir step 2 check karo.)
- Check karo ki conflict order-dependent hai ya nahi. IF (jo PC compute karta hai) har instruction ke liye har cycle hota hai. EX arithmetic instructions ke liye hota hai. Reordering change karta hai ki EX mein kaunsi instruction hai, na yeh fact ki koi instruction hamesha IF mein hai. Yeh step kyun? Instruction-Level Parallelism scheduling sirf un hazards mein help karta hai jo depend karte hain ki kaunsi instructions adjacent hain; yeh wala nahi.
- Conclusion: reordering se avoid nahi hoga. Kyunki IF har cycle adder demand karta hai, EX mein koi bhi instruction collide karegi. structural hai, schedule-dependent nahi. Yeh step kyun? Structural hazards (physical shortage) ko Data Hazards / Control Hazards (jinhe reordering soften kar sakti hai) se distinguish karta hai.
- Asli fix: ek dedicated PC incrementer. IF stage mein sirf PC ke liye ek alag sasta 32-bit adder sharing khatam karta hai, is hazard ka par la deta hai. Yeh step kyun? Parent note ke "add a cheap adder" resolution se match karta hai — ek adder ki cost ≪ endless stalls ki cost.
Forecast check: yeh fundamentally ek hardware shortage hai — reordering ise dodge nahi kar sakta; sirf dedicated adder kaam karta hai. Agar tumne "hardware shortage" guess kiya tha, sahi.
Verify: Logical claim: agar koi resource har cycle ek stage se demand kiya jaata hai, toh koi bhi instruction permutation clash nahi hatati → reordering fail; sirf extra hardware kaam karta hai. Parent ki structural (resource) hazard ki definition se consistent. ✓ (Koi numeric check nahi — yeh cell by design conceptual hai.)
Example 9 — Cell I: superscalar port-count degenerate case
Forecast: sirf 3 read ports hain lekin 4 reads demand hain — kya stall hoga, aur kitna? (Guess karo, phir count follow karo.)
- Demanded vs available reads count karo. Demand reads this cycle; supply read ports. Shortfall read jo serve nahi ho sakta. Yeh step kyun? Port hazard purely "demand supply" hai — dono sides count karo.
- Extra access serialize karne ke liye stall karo. Unserved read wait karega, toh register access cycle ki jagah cycles mein spread ho jaata hai: penalty bubble. Yeh step kyun? Teen ports ek cycle mein maximum reads serve kar sakte hain; tha read ke liye is cycle mein koi port nahi, toh by definition woh next cycle mein slip karta hai — woh slip hi single stall cycle hai.
- Write check. Writes demanded , write ports → supply meets demand, is cycle mein koi write conflict nahi. Yeh step kyun? Hume har port type cover karna hai; reader ko kabhi assume nahi karna chahiye ki writes theek hain bina supply vs demand check kiye.
- Master formula mein daalo. Maano un cycles ka fraction hai jahan yeh read-port shortage hoti hai, ke saath. Read-port hazard sum mein ek term contribute karta hai (yahan index ). Worst case lete hain jahan har issue clash kare, , toh . Yeh step kyun? Page ne promise kiya tha ki har cell se route karta hai; port hazard simply ek aur term hai, aur uska worst case deta hai.
Forecast check: haan stall hoga — exactly 1 cycle ka, worst-case CPI 2.0 push ho jaata hai. Agar tumne "1 cycle stall" guess kiya tha, sahi.
Verify: Reads ports → hazard, minimum stall cycle. Writes → OK. Worst-case CPI . Fix (4th read port add karo) demand supply set karta hai, ko par le jaata hai, aur stall khatam karta hai — parent ki "more ports" strategy se match karta hai. ✓
Recall Cells par quick self-test
Kaun sa cell bada CPI deta hai, "frequent-cheap" () ya "rare-costly" ()? ::: Frequent-cheap: , toh CPI . Products compare karo. Kya instruction reordering ek structural hazard ko remove kar sakta hai jo har cycle hit karta ho? ::: Nahi — yeh hardware shortage hai, ordering problem nahi; sirf extra hardware (ya stall accept karna) help karta hai. wale program ka single-port memory par memory-hazard CPI kya hoga? ::: Exactly — stall term vanish ho jaata hai.