Microprocessor and Computer ArchitectureUnit 911 min read
Pipelining & Performance: Speeding Up Computers
Unit 9 of Microprocessor and Computer Architecture explores how pipelining divides instruction execution into stages to boost CPU throughput, compares hardwired vs. microprogrammed control, and analyzes performance metrics like CPI and clock cycles—with real-world examples from Nepalese apps and hardware.
TAKEAWAYS:
- Pipelining splits instruction execution into 5 stages (IF, ID, EX, MEM, WB) to overlap operations and increase instructions per cycle (IPC).
- Hazards (structural, data, control) disrupt pipelines, requiring stalls or forwarding to maintain efficiency.
- Performance metrics (CPI, clock cycles, MIPS) quantify speedups, with pipelining reducing average CPI below 1.
- Superpipelining and superscalar architectures extend pipelining to deeper stages or wider execution units.
- Real-world apps like eSewa’s payment processing and Pathao’s route optimization rely on pipelined CPUs for low-latency responses.
- Exam focus: Define pipelining, draw the 5-stage pipeline, explain hazards, and calculate speedup for given CPI values.
1. Why Pipelining? The Bottleneck Problem
Computers execute instructions sequentially: fetch → decode → execute → memory access → writeback. Without pipelining, the CPU idles while waiting for each stage to finish. For example, if a CPU takes 4 clock cycles to complete one instruction, it processes 1 instruction per 4 cycles—wasting 75% of its potential.
Real-world analogy:
- Pathao’s driver matching system must process thousands of ride requests per second. Without pipelining, each request would block the next, causing delays. Pipelining lets the system fetch a new request while the previous one is being executed, reducing average wait time.
2. The 5-Stage Pipeline: How It Works
Pipelining divides instruction execution into 5 parallel stages, each taking 1 clock cycle. While one instruction is in the Execute (EX) stage, the next can be Decoded (ID), and another Fetched (IF).
| Stage | Task | Example (ADD B,C) | Clock Cycle |
|---|---|---|---|
| IF | Fetch instruction from memory | Load ADD B,C from address 0x100 |
1 |
| ID | Decode opcode, fetch operands | Decode ADD, load B and C from regs |
2 |
| EX | Execute ALU operation | ALU computes B + C |
3 |
| MEM | Memory access (if needed) | Store result to memory (if STORE) |
4 |
| WB | Write result to register | Save B + C to register D |
5 |
Visual:
graph LR
subgraph Pipeline Stages
IF["IF: Fetch"] -->|"1 cycle"| ID["ID: Decode"]
ID -->|"1 cycle"| EX["EX: Execute"]
EX -->|"1 cycle"| MEM["MEM: Memory"]
MEM -->|"1 cycle"| WB["WB: Writeback"]
end
**Throughput**:
1 instruction per cycle
(vs. 1 per 5 cycles without pipelining)
end noteWorked Example: Speedup Calculation Assume a CPU without pipelining takes 5 cycles per instruction (CPI = 5). With pipelining, CPI = 1 (ideal case).
- Speedup = Old CPI / New CPI = 5 / 1 = 5× faster.
- Real-world tie-in: Nepal Rastra Bank’s transaction processing uses pipelined servers to handle thousands of online payments (via eSewa/Khalti) per second without delays.
3. Hazards: When Pipelining Breaks Down
Even with pipelining, 3 types of hazards can stall the pipeline:
| Hazard Type | Cause | Example | Solution |
|---|---|---|---|
| Structural | Two instructions need the same resource at once | ADD and MUL both need the ALU in EX stage |
Add a second ALU or stall the pipeline |
| Data | An instruction depends on the result of a previous one | ADD D,B,C followed by SUB E,D (WB not done yet) |
Forwarding or stall |
| Control (Branch) | A branch instruction changes the next instruction to fetch | JMP or CALL after ADD |
Delay slot or branch prediction |
Visual: Data Hazard Example
Real-world example:
- NTC’s ticket booking system uses pipelining but must handle data hazards when checking seat availability. If
Instruction 1updates seatA1andInstruction 2checksA1, a stall ensures the correct data is read.
4. Performance Metrics: Measuring Speedups
Key metrics to evaluate pipelining:
| Metric | Formula | Example | Interpretation |
|---|---|---|---|
| CPI | Cycles per Instruction | Pipelined: CPI = 1 (ideal) | Lower CPI = faster |
| Clock Cycle | Time per cycle | 1 GHz = 1 ns per cycle | Faster clock = more instructions/sec |
| MIPS | Millions of Instructions per Second | MIPS = Clock Rate / CPI | Higher MIPS = better performance |
| Speedup | Old Time / New Time | 5-cycle → 1-cycle = 5× speedup | Pipelining reduces average CPI |
Worked Example: Calculating MIPS
- A pipelined CPU runs at 2 GHz (2 × 10⁹ cycles/sec) with CPI = 1.2 (due to hazards).
- MIPS = (2 × 10⁹) / (1.2 × 10⁶) = 1.67 × 10³ MIPS ≈ 1670 MIPS.
Real-world tie-in:
- Google’s data centers use pipelined CPUs to achieve >10,000 MIPS per server, enabling real-time searches and ad targeting.
5. Advanced Pipelining Techniques
To further improve performance, architects use:
| Technique | Description | Example |
|---|---|---|
| Superpipelining | Deeper pipeline (e.g., 8 stages) to increase clock speed | Intel’s early Pentium CPUs |
| Superscalar | Multiple execution units (e.g., 2 ALUs) to execute >1 instruction per cycle | Modern x86 CPUs (e.g., Intel Core i7) |
| Out-of-Order Exec | Reorders instructions to avoid stalls (used with Tomasulo’s algorithm) | ARM Cortex-A series |
| VLIW | Very Long Instruction Word: bundles multiple operations into one instruction | TI’s C6000 DSPs (used in audio processing) |
Visual: Superscalar Pipeline
Real-world example:
- WhatsApp’s servers use superscalar CPUs to handle millions of messages/sec, processing encryption and routing in parallel.
6. Trade-offs: Pros and Cons of Pipelining
| Advantages | Disadvantages |
|---|---|
| ✅ Higher throughput: 1 instruction per cycle (vs. 1 per 5 cycles) | ❌ Complexity: More hardware for forwarding/stalls |
| ✅ Faster execution for long programs | ❌ Hazards: Stalls reduce actual speedup |
| ✅ Lower CPI (closer to 1) | ❌ Branch mispredictions waste cycles |
| ✅ Energy efficiency (shorter idle times) | ❌ Debugging harder: Pipeline state is distributed |
Real-world trade-off:
- Nepal’s NEPSE stock trading system uses pipelined servers for low-latency order matching, but branch mispredictions (e.g., in volatile markets) can cause temporary slowdowns.
7. Real-World Applications in Nepal
eSewa/Khalti Payments
- Idea Used: Pipelined transaction processing to handle 10,000+ payments/sec during Dashain.
- How: Each payment goes through stages:
- IF: Fetch user details
- ID: Validate amount
- EX: Deduct from account
- MEM: Update bank DB
- WB: Send confirmation SMS.
Pathao’s Driver Matching
- Idea Used: Superpipelining to match riders to drivers in <500ms.
- How: Parallel stages for:
- Location fetch (IF)
- Driver availability check (ID)
- Route calculation (EX)
- Notification send (MEM/WB).
NTC’s Ticket Booking
- Idea Used: Data hazard handling to prevent double-booking.
- How: If
Instruction 1books seatA1andInstruction 2checksA1, the pipeline stalls untilA1is marked as booked.
Exam Tip
What examiners want to see:
- Definition: Pipelining is "dividing instruction execution into parallel stages to overlap operations and increase throughput."
- 5-Stage Pipeline Diagram: Draw and label IF, ID, EX, MEM, WB with arrows showing overlap.
- Hazard Examples: For each hazard type (structural, data, control), give one example and its solution.
- Speedup Calculation: If given CPI before/after, calculate speedup as:
Example: If CPI drops from 4 to 1.5, speedup = 4 / 1.5 ≈ 2.67×.Speedup = Old CPI / New CPI - Real-World Link: Relate to eSewa, Pathao, or NTC in your answer (e.g., "Like Pathao’s driver matching, pipelining reduces average wait time by overlapping stages.").
Common Mistakes to Avoid:
- ❌ Forgetting to mention hazards (examiners love this!).
- ❌ Drawing a pipeline with non-overlapping stages (show overlap with arrows).
- ❌ Ignoring CPI > 1 in real systems (always mention stalls/hazards reduce ideal speedup).
Final Visual Summary:
Based on the TU BIT syllabus for Microprocessor and Computer Architecture (BIT151), unit 9.
Discussion
Loading…