๐ Computer Architecture: IO Systems
The Story of How Your Computer Talks to the World
Imagine your computer is a super smart brain sitting in a room. But this brain needs to talk to things outside the room โ a keyboard, a mouse, a printer, a screen. How does it do that?
Thatโs what IO Systems (Input/Output Systems) are all about!
Think of it like this: Your brain (CPU) is the boss inside the office. But the boss needs helpers to send messages to the outside world and receive messages back.
๐ฎ IO Devices: The Messengers
What Are IO Devices?
IO Devices are like messengers between your computer and you!
- Input Devices = Send information TO your computer
- Output Devices = Get information FROM your computer
Simple Examples
| Type | Device | What It Does |
|---|---|---|
| Input | Keyboard | You type โ Computer receives letters |
| Input | Mouse | You click โ Computer knows where |
| Input | Microphone | You talk โ Computer hears sound |
| Output | Monitor | Computer โ Shows you pictures |
| Output | Speaker | Computer โ Plays sound for you |
| Output | Printer | Computer โ Prints on paper |
The Speed Problem ๐ข๐
Hereโs something important: Devices are SLOW compared to the CPU!
Speed Comparison:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
CPU: 1,000,000,000 ops/sec
SSD: 500,000 ops/sec
Hard Disk: 1,000 ops/sec
Keyboard: 10 ops/sec
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Your CPU is like a race car. Your keyboard is like a turtle. The CPU has to WAIT for slow devices!
๐ IO Interfaces: The Translators
Whatโs an Interface?
Imagine you speak English, but your friend speaks Spanish. You need a translator to talk to each other!
IO Interfaces are translators between the CPU and devices. They:
- Convert signals โ Device language โ CPU language
- Control timing โ Make fast CPU wait for slow device
- Handle data โ Package information properly
Types of Interfaces
graph TD A[CPU] --> B[IO Interface] B --> C[Device] B --> D[Serial Interface<br/>One bit at a time<br/>USB, HDMI] B --> E[Parallel Interface<br/>Many bits at once<br/>Old printer ports]
Real World Example
USB = Universal Serial Bus
- โUniversalโ = Works with many devices
- โSerialโ = Sends bits one after another
- โBusโ = A shared road for data
When you plug in a USB mouse:
- Mouse sends signals
- USB Interface translates them
- CPU understands your clicks!
โฐ Polling vs Interrupts: Two Ways to Check Mail
The Polling Method ๐ฌ
Polling = Keep checking over and over!
Imagine waiting for a package:
โIs it here yet?โ (No) โIs it here yet?โ (No) โIs it here yet?โ (No) โIs it here yet?โ (YES!)
This is how polling works:
CPU asks: "Keyboard, any key pressed?"
Keyboard: "No"
CPU asks: "Keyboard, any key pressed?"
Keyboard: "No"
CPU asks: "Keyboard, any key pressed?"
Keyboard: "Yes! Letter 'A'!"
CPU: "Got it!"
Problem: CPU wastes time asking again and again!
The Interrupt Method ๐
Interrupts = Ring a bell when ready!
Now imagine you put a doorbell for the delivery person:
You do other workโฆ DING DONG! โOh! Package is here!โ
This is how interrupts work:
CPU: *doing math work*
Keyboard: *RING RING!* "Hey! Key pressed!"
CPU: "OK! Let me check what key."
CPU: "It's letter 'A'. Got it!"
CPU: *goes back to math work*
Comparison Table
| Feature | Polling | Interrupts |
|---|---|---|
| How it works | CPU keeps asking | Device rings a bell |
| CPU time | Wastes time | Saves time |
| Response speed | Can be slow | Very fast |
| Best for | Simple systems | Modern computers |
When to Use Which?
graph TD A[Need to check device?] --> B{How often?} B -->|Very rarely| C[Use Polling<br/>Simple to code] B -->|Very often| D[Use Interrupts<br/>CPU can do other work]
๐ DMA Transfers: The Express Delivery
The Problem with Regular Transfers
Normally, when you copy a big file:
- CPU reads piece from hard disk
- CPU stores piece in memory
- CPU reads next piece from hard disk
- CPU stores next piece in memory
- โฆ repeat 1000 times โฆ
The CPU does ALL the work! Like the boss carrying boxes himself.
DMA = Direct Memory Access
DMA is like hiring a delivery truck driver!
The CPU says: โHey DMA, copy this file from disk to memory. Tell me when done.โ
Then the CPU goes back to other work while DMA handles the copying!
graph TD A[Without DMA] --> B[CPU copies<br/>every byte<br/>CPU is BUSY] C[With DMA] --> D[CPU starts transfer] D --> E[DMA copies bytes<br/>CPU is FREE] E --> F[DMA: Done!<br/>Interrupts CPU]
How DMA Works Step by Step
-
CPU sets up DMA:
- โCopy from: Disk address 500โ
- โCopy to: Memory address 1000โ
- โHow much: 5000 bytesโ
- โGO!โ
-
DMA takes control of the bus
- Like borrowing the road
-
DMA copies data directly
- Disk โ Memory (no CPU involved!)
-
DMA finishes and rings the bell
- Sends interrupt to CPU
- โBoss, Iโm done!โ
Why DMA is Amazing
| Without DMA | With DMA |
|---|---|
| CPU does 100% of copying | CPU does 1% (setup only) |
| CPU canโt do other work | CPU is free to work |
| SLOW for big files | FAST for big files |
๐ IO Scheduling: Taking Turns Fairly
The Traffic Problem
Imagine many cars trying to use ONE road. Without rules = chaos!
Same with IO: Many programs want to read/write to ONE disk. Who goes first?
IO Scheduling = The traffic rules for disk access!
Common Scheduling Methods
1. FCFS (First Come, First Served)
Like a queue at a store. First person in line gets served first.
Request order: A, B, C, D
Service order: A, B, C, D
Simple but NOT efficient!
2. SSTF (Shortest Seek Time First)
Like a delivery driver who goes to the NEAREST house first.
Disk head at position 50
Requests: 20, 45, 80, 10
SSTF picks: 45 (closest!)
Then: 80
Then: 20
Then: 10
3. SCAN (Elevator Algorithm)
Like an elevator that goes UPโฆ then DOWNโฆ then UPโฆ
graph LR A[0] --> B[50] --> C[100] C --> D[50] --> E[0] style B fill:#90EE90
The disk head sweeps back and forth!
4. C-SCAN (Circular SCAN)
Like an elevator that only goes UP, then jumps back to bottom.
- Goes: 0 โ 100
- Jumps back to 0
- Goes: 0 โ 100 again
More fair than regular SCAN!
Quick Comparison
| Method | Good For | Bad For |
|---|---|---|
| FCFS | Simple systems | Efficiency |
| SSTF | Speed | Fairness |
| SCAN | Balance | Simple needs |
| C-SCAN | Fairness | Simple needs |
๐ฏ Putting It All Together
Letโs trace what happens when you press a key:
graph TD A[You press 'A'] --> B[Keyboard sends signal] B --> C[IO Interface translates] C --> D[Interrupt sent to CPU] D --> E[CPU checks keyboard] E --> F[CPU stores 'A' in memory] F --> G[Letter appears on screen!]
The Big Picture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ YOUR COMPUTER โ
โ โ
โ โโโโโโโโโโโ โ
โ โ CPU โโโโโโ Interrupts โโโโโ โ
โ โโโโโโฌโโโโโ โ โ
โ โ โ โ
โ โผ โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โ โ
โ โ DMA โโโโโบโ Memory โ โ โ
โ โโโโโโฌโโโโโ โโโโโโโโโโโ โ โ
โ โ โ โ
โ โผ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ IO Interfaces โโโโโโโโ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโโโ โ
โ โ โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ IO Devices โ
โ (Keyboard, โ
โ Mouse, Disk) โ
โโโโโโโโโโโโโโโโโโโ
๐ Key Takeaways
- IO Devices = Messengers between you and computer
- IO Interfaces = Translators that connect devices to CPU
- Polling = Keep asking (wastes CPU time)
- Interrupts = Ring a bell when ready (saves CPU time)
- DMA = Express delivery without bothering the CPU
- IO Scheduling = Traffic rules for disk access
๐ก Remember This Analogy!
Your computer is like a busy office:
- CPU = The Boss
- IO Devices = Mailroom workers (slow but important)
- IO Interfaces = Translators
- Polling = Boss keeps checking mailroom
- Interrupts = Mailroom rings bossโs phone
- DMA = Delivery truck (moves stuff without boss)
- IO Scheduling = Rules for who uses the delivery truck first
Now you understand how your computer talks to the world! ๐