Lesson 11 — Intermediate

Instruction Pipelining

Ek instruction ko alag-alag stages mein tod ke saare instructions ko ek saath andar daal do — ye pipelining hai, CPU ki sabse important speedup technique. Is lesson mein hum dekhenge stages kya hain, timing diagram kaise padhte hain, aur speedup/throughput/efficiency ke formulas jo GATE ka dil jeete hain.

⏱ 15 min• Intermediate• System Buses

Pipelining kya hai

WHAT

Pipelining mein har instruction ko kai chhote stages (jaise IF, ID, EX, MEM, WB) mein toda jaata hai aur har stage apne kaam mein expert ban jaati hai — jaise assembly line. Ek time mein instructions ke alag-alag stages chal rahe hote hain.

WHEN

Jab instruction chala rahe ho — pipelining sirf throughput badhati hai (cycle-to-cycle), single instruction ka time kam nahi karta. N instruction ho tab fayda dikhta hai.

WHERE

Har modern processor mein — RISC toh isi par design hota hai, CISC bhi andar mein micro-ops pipeline chalati hai (x86).

Juice stall wala example socho — ek banda sab karta tha toh ek glass2 minute. Chaar banda laga ke har station ek kaam kare toh har minute ek glass. Ek glass ka time same, output 4× — yahi pipelining hai.

Stages aur timing diagram

CLASSIC 5-STAGE PIPELINE (MIPS jaisa) :
  IF  : Instruction Fetch — memory se instruction padho (PC se)
  ID  : Instruction Decode — samjho kya hai + registers padho
  EX  : Execute — ALU operation / address calculate / branch
  MEM : Memory access — LOAD/STORE ke liye memory read/write
  WB  : Write Back — result register mein likho

TIMING (har column = ek clock cycle) :
       C1   C2   C3   C4   C5   C6   C7
  I1   IF   ID   EX   MEM  WB
  I2        IF   ID   EX   MEM  WB
  I3             IF   ID   EX   MEM  WB
  I4                  IF   ID   EX   MEM  WB

→ C4 ke baad har cycle ek NAYI instruction complete (throughput = 1/cycle)
→ pehla result C5 mein, phir har cycle ek naya result

Diagram padhne ka rule: har instruction left-shifted ek column. Stall ho toh wahan gap daalo (agla lesson mein hazards). Pipeline ka cycle time = slowest stage + register latch overhead — isliye stages ko barabar chhota rakha jaata hai.

Yaad rakho: Pipelining ka faida THROUGHPUT mein hai (per unit time zyada instructions), latency mein nahi — ek instruction ab bhi 5 cycles leti hai (overhead ke saath thoda zyada). Ye line interview mein zaroor boliyo.

Speedup, throughput, efficiency — formulas + numerical

NON-PIPELINED time : T = n × k × t
  n = instructions, k = stages, t = ek stage/cycle time

PIPELINED time : T = (k + n - 1) × t
  pehla instruction k cycles, baaki sabko ek-ek cycle

SPEEDUP = (n × k) / (k + n - 1)
  n → ∞ par Speedup → k   (MAX speedup = number of stages)

THROUGHPUT = n / T_pipeline
EFFICIENCY = Speedup / k   (utilisation of stages)

NUMERICAL : k = 5 stages, t = 2 ns, n = 100 instructions
  Non-pipe = 100 × 5 × 2 = 1000 ns
  Pipe     = (5 + 100 - 1) × 2 = 208 ns
  Speedup  = 1000 / 208 ≈ 4.81  (ideal max = 5)

Perfect linear speedup tabhi jab sab stages EQUAL time lein

Formula ka logic yaad rakho: pipeline mein sirf pehla instruction poora k (stages) leta hai, baaki n−1 instructions ek-ek cycle mein bahar nikalte hain. Isliye (k + n − 1).

GATE trap: Maximum speedup = k (number of stages) — n→∞ limit mein. Aur agar stages unequal hon (sabse bada stage 3ns, baaki 1ns) toh cycle time sabse bade stage par padta hai — speedup utna hi milega jitna balance ho.

Pipeline ke types aur design points

Pipeline depth ka trade-off :
  stages zyada chhoti → clock tez (GHz badhta)
  lekin : branch penalty zyada, hazards zyada, power zyada

  Example : 5-stage (classic, 1 GHz)
            14-20 stage (modern superscalar, 4-5 GHz)

Superscalar : ek cycle mein 2-4 instructions issue
  = do parallel pipelines + dynamic scheduling (OOO execution)
Concept link: Pipeline hazards (agla lesson) isi design ka side effect hain — stages jitni chhoti aur deep, hazards utne zyada. Isliye forwarding, prediction jaise techniques nehiye bina modern pipeline nahi chalti.

Exercise

Question: 5-stage pipeline mein memory access (load/store) kaunse stage mein hota hai? (mem / id / wb)

Question: k stages, n instructions, equal stages wale pipeline ka time (n + k - 1) × kya hota hai? (clock cycle time / instruction count)

Question: Ideal case mein pipeline ki maximum speedup kitni hoti hai — stages ki sankhya (k) ya instructions ki (n)?

Common mistakes

Desi example: Paneer tikka assembly line

Stall ka setup dekho — ek banda vs chhote stations wali line. Yahi pipelining ka asli farak hai:

text
Ek banda : cut → marinate → skewer → grill = 4 min/plate
4 stations : har station ek hi kaam
  har 1 min mein ek plate OUT (throughput 4×)
Ek plate ki latency : phir bhi 4 min (kam nahi hui)
Pipeline = station wise expert + round the clock flow
Exam mapping (GATE / TCS / Interviews)
  • GATE: speedup/throughput numerical — COA ka sabse frequent numerical (2-3 marks).
  • GATE: unequal stage delays se cycle time decide karna.
  • Interview: "5 stages ka naam batao" — IF, ID, EX, MEM, WB (ratto mat, samjho).
  • Trap: "Pipelining reduces instruction latency" — galat, wo throughput hai.
Lesson complete?

Pipeline ke formulas clear. Agla lesson — Pipeline Hazards & Stalls — mein dekhenge ye rukawatein aati kahan se hain aur unhe kaise hatate hain.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course