5.2.5 · HinglishProcessor Datapath & Pipelining

Structural hazards

3,513 words16 min readRead in English

5.2.5 · Hardware › Processor Datapath & Pipelining

Structural Hazard kya hota hai?

YEH KYUN hota hai: Pipelining ka goal hai multiple instructions ek saath execute karna, lekin hardware resources finite aur aksar shared hote hain. Cost aur complexity kam karne ke liye, designers sirf ek hi instance rakh sakte hain mehenga components ka (memory, multipliers). Jab do stages ko ek hi time par woh component chahiye, toh structural hazard ho jaata hai.

KYA hota hai: Pipeline mein ek stall daalna padta hai (jise bubble ya pipeline interlock bhi kehte hain). Jo instruction aage nahi badh sakti, woh ek ya zyada clock cycles tak resource free hone ka wait karti hai.

PERFORMANCE par ASAR: Har stall ek clock cycle waste karta hai jisme koi naya kaam nahi hota. Agar hazard baar baar aata rahe, toh effective CPI ideal 1.0 se zyada ho jaata hai.

Common Causes aur Examples

1. Single-Port Memory (Sabse Common)

PROBLEM YEH HAI: Classic MIPS mein alag instruction aur data caches hote hain, lekin ek aise system ko socho jisme sirf ek unified memory ho:

  • Cycle 1: Instruction A, IF (Instruction Fetch) mein hai, memory read kar rahi hai
  • Cycle 4: Instruction D, MEM (Memory access) mein hai, data read/write kar rahi hai

Agar dono ek saath memory access karne ki koshish karein, toh structural hazard ho jaata hai.

YEH DESIGN KYUN EXIST KARTA HAI: Dual-ported memory (alag instruction aur data ports) mehenga hota hai. Kuch embedded systems cost/power bachane ke liye single-port memory use karte hain. Harvard architecture (alag instruction/data memories) is hazard se bachta hai lekin zyada hardware maangta hai.

2. Insufficient Functional Units

3. Register File Ports

Register file ko chahiye:

  • Read ports: ID stage do source registers read karta hai (jaise, rs, rt)
  • Write port: WB stage ek destination register likhta hai (rd)

Hazard tab agar: Ek cycle mein 2 se zyada reads ya 1 se zyada writes ki koshish ho.

Mathematical Analysis: Performance Impact

Chaliye effective CPI derive karte hain jab structural hazards aate hain.

YEH FORMULA KYUN?: Har stall ek cycle add karta hai jisme pipeline koi useful kaam nahi karta. Hazards ki frequency instruction mix (kitni baar memory access karte hain, specific units use karte hain) aur pipeline structure (kitne stages conflict kar sakte hain) par depend karti hai.

Scratch se Derivation:

  1. Ideal throughput: Har cycle mein ek instruction complete → CPI = 1.0
  2. Stall insertion: Jab hazard aata hai, ek "bubble" (NOP) insert karo. Jo instruction conflicting stage mein enter karne wali thi, woh ek cycle wait karti hai.
  3. Stalls count karna: Agar probability hai ki hazard har instruction par aata hai, aur har hazard cycles cost karta hai, toh:
  4. Total CPI:

Memory hazards ke liye aur ke saath:

Structural Hazards ke Solutions

KONSA CHOOSE KAREIN?:

  • High-performance processors: Hardware add karo (cost, performance se justify hoti hai)
  • Embedded systems: Occasional stalls tolerate karo (area/power critical hai)
  • Modern CPUs: Separate I/D caches standard hain; structural hazards zyaadatar eliminate ho gaye hain

Structural vs. Data vs. Control Hazards

Recall Ek 12-saal ke bachche ko explain karo

Tum apne dost ke saath video game khel rahe ho, ek single controller pe baari-baari. (Controller processor mein ek "resource" ki tarah hai.)

Structural hazard: Tumhe dono ko controller ki zaroorat hai bilkul ek hi time par buttons press karne ke liye. Kyunki sirf ek controller hai, tumhe se ek ko wait karna padega. Yahi structural hazard hai—jitne log chahein utne controllers (hardware) nahi hain abhi.

Data hazard: Tumhe apni baari lene se pehle dekhna hai ki tumhare dost ne kya kiya (jaise unke move dekhne ka wait karna phir apna move karne ke liye). Yeh tumhare beech order aur information pass hone ke baare mein hai.

Control hazard: Tum dekh rahe ho ki tumhara dost boss ko beat karta hai ya nahi, taaki decide kar sako ki retry karni chahiye ya next level pe jaana chahiye. Yeh decisions ke baare mein hai jo decide karta hai tum aage kya karte ho.

Structural hazards sabse simple hain: bas jab sabko ek saath "cheez" chahiye hoti hai toh enough "cheez" nahi hoti!

| Hazard Type | Cause | Solution | |-------------|----------| | Structural | Hardware resource conflict | Resources add karo, stall karo | | Data | Instruction pichle result par depend karti hai | Forwarding, stall | | Control | Branch outcome unknown | Prediction, stall |

KEY INSIGHT: Structural hazards only hardware limitations se aate hain, instruction sequence se nahi. Data aur control hazards unlimited hardware ke saath bhi hote hain—yeh dependencies aur decisions ke baare mein hain. Structural hazards enough paison se eliminate ho sakte hain (har resource duplicate karo), lekin data/control hazards algorithm ke liye fundamental hain.

Common Mistakes aur Steel-Manning

Worked Example: Hazard Scenario Analyze Karna

Connections

  • Pipelining Fundamentals - Structural hazards teen hazard types mein se ek hain
  • Data Hazards - Resource conflicts vs. data dependencies compare karo
  • Control Hazards - Branch prediction vs. hardware duplication trade-offs
  • Memory Hierarchy - Alag I/D caches memory structural hazards eliminate karte hain
  • Superscalar Processors - Multiple issue mein bahut zyada resources chahiye, zyada structural hazards
  • Pipeline Stalls - Saare hazard types handle karne ka mechanism
  • Instruction-Level Parallelism - Resource constraints ILP extraction ko limit karte hain

#flashcards/hardware

Structural hazard kya hota hai? :: Ek pipeline hazard jo resource conflicts se hota hai jab multiple instructions ko ek hi saath ek hi hardware component chahiye (jaise memory, ALU, register ports).

Basic pipelined processors mein sabse common structural hazard ka cause kya hai?
Single-port unified memory: instruction fetch (IF stage), data access (MEM stage) se conflict karta hai.
Structural hazard CPI ko kaise affect karta hai?
Yeh CPI ko 1.0 se upar le jaata hai stalls insert karke. CPI_actual = CPI_ideal + (frequency of hazard × stall penalty).
Structural hazards ke do main solutions kya hain?
(1) Hardware resources add karo (memory, functional units, ports duplicate karo) conflicts eliminate karne ke liye. (2) Shared resource ka access serialize karne ke liye pipeline stalls insert karo.
Modern high-performance processors mein structural hazards kyun kam hain?
Yeh alag instruction aur data caches (Harvard architecture), multiple functional units, aur multi-ported register files use karte hain, conflicts avoid karne ke liye resources duplicate karte hain.
Structural hazard, data hazard se alag kaise hai?
Structural: hardware resource conflict (enough hardware nahi). Data: instruction dependency (result ka wait). Structural hardware add karke eliminate ho sakta hai; data hazards algorithmic hain.
Ek single structural hazard stall ki performance penalty kya hai?
Har stall mein ek clock cycle. Agar stalls frequent hain (jaise 30% instructions), CPI 1.0 se 1.3 tak badh sakta hai, ~23% performance kho ke.
Ek designer kab structural hazards accept kar sakta hai hardware add karne ki jagah?
Cost/power-sensitive embedded systems mein, ya jab hazard itna rare ho ki performance loss, hardware duplicate karne ki cost ke comparison mein acceptable ho.

Concept Map

shares

conflict causes

overlaps

compete for

from

from

from

IF vs MEM clash

resolved by

wastes

raises

avoided by

Pipelining

Finite Hardware Resources

Structural Hazard

Stages in Same Cycle

Single-Port Memory

Shared Functional Units

Register File Ports

Stall or Bubble

Wasted Clock Cycle

CPI Above 1.0

Separate I and D Caches