Docsity

Structural Hazards in Computer Architecture: Overview and Solutions, Lecture notes of Computer Science

Partial preview of the text

Download Structural Hazards in Computer Architecture: Overview and Solutions and more Lecture notes Computer Science in PDF only on Docsity!

Pipelining

HCT

Instruction Cycle State Diagram

Appendix A - Pipelining 4 What Is Pipelining

  • (^) Laundry Example
  • (^) Ann, Brian, Cathy, Dave

each have one load of clothes

to wash, dry, and fold

  • (^) Washer takes 30 minutes
  • (^) Dryer takes 40 minutes
  • (^) “Folder” takes 20 minutes

A B C D

Appendix A - Pipelining 5 What Is Pipelining

Sequential laundry takes 6 hours for 4 loads

If they learned pipelining, how long would laundry take?

A

B

C

D

6 PM 7 8 9 10 11 Midnight T a s k O r d e r Time

Chapter 4 — The Processor — 7 Pipelining Analogy

  • (^) Pipelined laundry: overlapping execution
    • (^) Parallelism improves performance 4.5 An Overview of Pipelining  Four loads: 

Speedup

 Non-stop: 

Speedup

= 2n/0.5n + 1.5 ≈

= number of

stages

Appendix A - Pipelining 8 Pipelining Lessons

  • (^) Pipelining doesn’t help latency of single task, it helps throughput of entire workload
  • (^) Pipeline rate limited by slowest pipeline stage
  • (^) Multiple tasks operating simultaneously
  • (^) Potential speedup = Number pipe stages
  • (^) Unbalanced lengths of pipe stages reduces speedup
  • (^) Time to “fill” pipeline and time to “drain” it reduces speedup

A

B

C

D

6 PM 7 8

T a s k O r d e r Time 30 40 40 40 40 20 What Is Pipelining

Pipeline

  • (^) In the previous slide, we completed 9 instructions in the time it would take to sequentially complete two instructions!
  • (^) Assumptions for simplicity
    • (^) Stages are of equal duration
  • (^) Things that can mess up the pipeline
    • (^) Structural Hazards – Can all stages can be executed in parallel? - (^) What stages might conflict? E.g. access memory
    • (^) Data Hazards – One instruction might depend on result of a previous instruction - (^) E.g. INC R1 ADD R2,R
    • (^) Control Hazards - Conditional branches break the pipeline
      • (^) Stuff we fetched in advance is useless if we take the branch

Branch Not Taken Branch Not taken Continue with next instruction as usual

Alternative Pipeline Depiction

Pipelining Hazards

  • (^) Hazards
    • (^) Structural hazards \
    • (^) Data Hazards
    • (^) Control Hazards
  • (^) Performance
  • (^) Controller implementation

Structural Hazards

  • (^) Attempt to use the same resource by two or more instructions at

the same time

  • (^) Example: Single Memory for instructions and data
    • (^) Accessed by IF stage
    • (^) Accessed at same time by MEM stage
  • (^) Solutions
    • (^) Delay the second access by one clock cycle, OR
    • (^) Provide separate memories for instructions & data
      • (^) This is what the book does
      • (^) This is called a “Harvard Architecture”
      • (^) Real pipelined processors have separate caches

Pipelined Example - Executing Multiple Instructions

  • (^) Consider the following instruction sequence: lw $r0, 10($r1) sw $sr3, 20($r4) add $r5, $r6, $r sub $r8, $r9, $r

Alternative View - Multicycle Diagram lw $r0, 10($r1)^ IM^ REG^ ALU^ DM^ REG sw $r3, 20($r4) add $r5, $r6, $r CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 CC 7 IM REG ALU DM REG IM REG ALU DM REG sub $r8, $r9, $r10 (^) IM REG ALU DM REG CC 8 Memory Conflict

One Memory Port Structural Hazards

I

n

s

t

r.

O

r

d

e

r

Time (clock cycles)

Load

Instr 1

Instr 2

Stall

Instr 3

Ifetch Reg ALU DMem Reg Ifetch Reg ALU DMem Reg Ifetch Reg ALU DMem Reg Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Ifetch Reg ALU DMem Reg Bubble Bubble Bubble Bubble Bubble