Lesson 13 — Intermediate

I/O Organization & Interrupts

CPU itna tez hai, aur devices itne dheeme — dono ka meet kahan hota hai? I/O organization mein. Is lesson mein hum dekhenge teeno tarike (polling, interrupt-driven, DMA), interrupt handling ka poora process, aur I/O addressing ke do tarike — ye interview aur exam dono ki jaan hain.

⏱ 14 min• Intermediate• Pipeline Hazards

I/O organization kya hai

WHAT

I/O organization ka matlab hai CPU aur input/output devices ke beech communication ke tarike. Kyunki device aur CPU ki speed alag hai, beech mein controller, buffers aur protocols chahiye — unka design isi topic mein aata hai.

WHEN

Har keyboard press, har disk read, har network packet — sab I/O events hain. CPU ko pata chalte hi ki device ready hai, tabhi transfer shuru hota hai.

WHERE

Keyboard, mouse, disk, printer, network — sab I/O hain. Unke controllers, ports aur interrupt lines isi organisation ka hissa hain.

Core sawaal ye hai: device ready hua ya nahi, CPU ko kaise pata chale? Isi ke teen jawab hain — poochhte raho (polling), interrupt do (interrupt-driven), ya seedha khud le lo (DMA).

Teen I/O techniques ka comparison

1) PROGRAMMED I/O (POLLING) :
   CPU baar baar device ka status register poochhta rehta hai
   "ready ho?" "ready ho?" — jab tak haan na bole
   → CPU ka time WASTED (busy waiting), simple design

2) INTERRUPT-DRIVEN I/O :
   Device khud interrupt deta hai jab ready ho
   → CPU apna kaam karta rehta hai, interrupt aane pe ISR chalata
   → polling se behtar (CPU free), chhote-chhote transfers ke liye

3) DMA (Direct Memory Access) :
   Poora BLOCK directly device ↔ memory (CPU sirf setup + done)
   → bade transfers (disk, network) ke liye BEST
   → CPU nearly free

Choice rule :
  chhota transfer + device bahut dheema = polling/interrupt
  bada block transfer = DMA (CPU bachao)

Speed ka logic samjho: polling mein CPU kaam waste karta hai, interrupt mein CPU sirf interrupt ke liye rukta hai, DMA mein CPU sirf 2 baar involve hota hai (setup aur completion). Transfer jitna bada, utna DMA zaroori.

Yaad rakho: Polling = CPU puchhe. Interrupt = device khud bole. DMA = device khud le le. Ye teeno ke beech ka farak har interview ka starter question hai — ek example ke saath bolo, selection confidence.

Interrupts aur handling ka process

INTERRUPT ka process :
1. Device IRQ line assert karta hai (hardware interrupt)
2. CPU current instruction complete karta hai (aur kai baar
   current stage flush) → uska state save (PC, flags push)
3. Interrupt vector table se ISR (Interrupt Service Routine)
   ka address uthao → PC wahan set
4. ISR chalta hai — device ko service karta hai (data padho, ack do)
5. IRET/RETI → saved state wapas, purane kaam pe aage

TYPES :
  Maskable     : CPU rok sakta hai (temporarily disable) — zyada tar
  Non-maskable : critical (fire/power fail) — hamesha sunna hai
  Vectored     : device khud batata hai ISR address (tez)
  Non-vectored : sabka ek hi fixed address → pehle identify karo
  Software     : INT instruction (trap, system call)

Nested interrupts : ek ISR ke andar doosra aaye (priority check)
Interview question: Q: "Interrupt ke time kya save hota hai?" — PC aur status flags (context), taaki wapas aa sake. Q: "Vectored vs non-vectored?" — vectored mein device seedha ISR address deta hai, non-vectored mein CPU pehle identify karta hai.

I/O addressing — memory mapped vs I/O mapped

MEMORY MAPPED I/O :
   device ko MEMORY ke address space ka hissa bana do
   ek hi address space, LOAD/STORE se access
   → instruction set chhota, decode simple

I/O MAPPED I/O (isolated) :
   device ka ALAG address space (I/O space)
   special instructions IN / OUT chahiye
   → memory aur I/O ke alag chips (separate read/write lines)

Dono ke signals :
  memory mapped : ek MREQ-type line
  I/O mapped    : IORQ/IOREQ + IN/OUT decode

Interrupt ke baad data lene ke tareeke :
  IN instruction (polled/ISR mein) ya DMA handshake

x86 family I/O mapped (IN/OUT) use karta hai, ARM mostly memory mapped. Doono ka farak — address space alag ya shared — ye classic short question hai.

Concept link: Pichhle lesson ke DMA ko yahan integrate karo — interrupt-driven se shuru (chhota transfer), DMA tak (bada block). Real systems teeno mix karte hain: interrupt se pata chalta hai, DMA se transfer hota hai.

Exercise

Question: Interrupt-driven I/O mein data transfer CPU ke through hota hai ya DMA ke through?

Question: Interrupt handle karne wala specific routine kya kehlata hai? (ISR / polling / vector)

Question: Polling mein device ka status kaise check hota hai — baar baar khud pooch kar ya ek baar?

Common mistakes

Desi example: Office ka kaam-mangwana

Office ke 3 tareeke — polling, interrupt, DMA — ko kaam ke flow se samjho:

text
Polling : boss har 5 min poochhta "file ready?" (CPU waste)
Interrupt : clerk bolta "sir, ho gaya" (CPU free, efficient)
DMA : clerk file khud utha ke cabinet mein rakh aaye,
      sirf bol gaya "rakh di" (setup + 1 interrupt, CPU free)
Chhota kaam = interrupt, mota kaam = DMA
Exam mapping (GATE / TCS / UGC)
  • GATE: interrupt handling ke steps aur context save ka order.
  • GATE: memory mapped vs I/O mapped — kaunsi instruction chahiye (IN/OUT).
  • TCS NQT: polling vs interrupt-driven — classic comparison.
  • Trap: "DMA uses interrupt per byte" — galat, per block ek interrupt (ya koi nahi, mode ke hisaab se).
Lesson complete?

I/O aur interrupts clear. Agla lesson — RISC vs CISC — mein compare karenge do processor philosophies jo aaj tak lad rahi hain.

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