Topic:
Data Hazards & Solutions
APPENDIX A - PIPELINING 1
Introduction
1 What is Pipelining?
2 The Major Hurdle of Pipelining-
Structural Hazards
Data Hazards
Control Hazards
3.solution of hurdles in pipelining.
2
What Is Pipelining
Laundry Example
A, B, C and D
each have one load of clothes
to wash, dry, and fold
Washer takes 30 minutes
Dryer takes 40 minutes
“Folder” takes 20 minutes
3
A B C D
What Is Pipelining
Sequential laundry takes 6 hours for 4 loads
If they learned pipelining, how long would laundry take?
4
A
B
C
D
30 40 20 30 40 20 30 40 20 30 40 20
6 PM 7 8 9 10 11 Midnight
T
a
s
k
O
r
d
e
r
Time
What Is Pipelining
Start work ASAP
Pipelined laundry takes 3.5
hours for 4 loads
5
A
B
C
D
6 PM 7 8 9 10 11 Midnight
T
a
s
k
O
r
d
e
r
Time
30 40 40 40 40 20
Pipelining Lessons
Pipelining doesn’t help latency of
single task, it helps throughput of
entire workload
Multiple tasks operating
simultaneously
Time to “fill” pipeline and time to
“drain” it reduces speedup
6
Pipeline Hurdles
Structural hazards
Data hazards
Control hazards
7
Pipeline Hurdles
Definition
Structural hazard
◦two different instructions use same h/w in same cycle
Data hazard
◦two different instructions use same storage
◦must appear as if the instructions execute in correct order
Control hazard
◦one instruction affects which instruction is next
8
Data Hazards
There are four types of Data Hazards
RAW (Read after Write)
WAR (Write after Read)
WAW (Write after Write)
RAR (Read after Read)
9
Data Hazards
Read After Write (RAW)
10
I: add r1,r2,r3
J: sub r4,r1,r3
I instruction
complete first
than j
instruction read
Data Hazards
Write After Read (WAR)
Write After Write (WAW)
11
I: sub r4,r1,r3
J: add r1,r2,r3
I: sub r1,r4,r3
J: add r1,r2,r3
Data Hazards
12
Read After Read (RAR)
I: sub r4,r1,r3
J: add r2,r1,r5
•Only RAW effects in pipelining
•WAR,WAW,RAR do not effects in
pipelining
Data Hazards
13
This is another
representation
of the stall.
LW R1, 0(R2) IF ID EX MEM WB
SUB R4, R1, R5 IF ID EX MEM WB
AND R6, R1, R7 IF ID EX MEM WB
OR R8, R1, R9 IF ID EX MEM WB
Example
ADD R3,R4,R5
SUB R1,R2,R3
DIV R1,R2,R3
ST R2,R4
MUL R4,R3,R2
14
Solution
1. F D E M WB
2. F - - - D E M WB
3. F D E M WB
4. F D E M WB
5. F - - - D E M WB
15
Example
1.ADD R3,R4,R5 > 2 clock cycle
2.SUB R1,R2,R3 > 4 clock cycle
3.DIV R1,R3,R2 > 5 clock cycle
16
Solution
1. F D E E M WB
2. F - - - - D E E E E M WB
3. - - - - F D - - - E E E E E M WB
17
Hazards solution
Forwarding:
To minimize or remove the stalls
Type of instruction:
Arithmetic> (add,sub,div,mul)
Movement> (load,store,move)
18
Forwording
19
1.ADD R3,R4,R5 > 2 clock cycle
2.SUB R1,R2,R3 > 4 clock cycle
3.DIV R1,R3,R2 > 5 clock cycle
4.LD R2,R1 > 3 clock cycle
Solution
20
1. F D E E M WB
2. F - - D E E E E M WB
3. F - - - - D E E E E E M WB
4. F - - - - - D E E E M WB
THANK YOU
21

Presentation copy

  • 1.
    Topic: Data Hazards &Solutions APPENDIX A - PIPELINING 1
  • 2.
    Introduction 1 What isPipelining? 2 The Major Hurdle of Pipelining- Structural Hazards Data Hazards Control Hazards 3.solution of hurdles in pipelining. 2
  • 3.
    What Is Pipelining LaundryExample A, B, C and D each have one load of clothes to wash, dry, and fold Washer takes 30 minutes Dryer takes 40 minutes “Folder” takes 20 minutes 3 A B C D
  • 4.
    What Is Pipelining Sequentiallaundry takes 6 hours for 4 loads If they learned pipelining, how long would laundry take? 4 A B C D 30 40 20 30 40 20 30 40 20 30 40 20 6 PM 7 8 9 10 11 Midnight T a s k O r d e r Time
  • 5.
    What Is Pipelining Startwork ASAP Pipelined laundry takes 3.5 hours for 4 loads 5 A B C D 6 PM 7 8 9 10 11 Midnight T a s k O r d e r Time 30 40 40 40 40 20
  • 6.
    Pipelining Lessons Pipelining doesn’thelp latency of single task, it helps throughput of entire workload Multiple tasks operating simultaneously Time to “fill” pipeline and time to “drain” it reduces speedup 6
  • 7.
  • 8.
    Pipeline Hurdles Definition Structural hazard ◦twodifferent instructions use same h/w in same cycle Data hazard ◦two different instructions use same storage ◦must appear as if the instructions execute in correct order Control hazard ◦one instruction affects which instruction is next 8
  • 9.
    Data Hazards There arefour types of Data Hazards RAW (Read after Write) WAR (Write after Read) WAW (Write after Write) RAR (Read after Read) 9
  • 10.
    Data Hazards Read AfterWrite (RAW) 10 I: add r1,r2,r3 J: sub r4,r1,r3 I instruction complete first than j instruction read
  • 11.
    Data Hazards Write AfterRead (WAR) Write After Write (WAW) 11 I: sub r4,r1,r3 J: add r1,r2,r3 I: sub r1,r4,r3 J: add r1,r2,r3
  • 12.
    Data Hazards 12 Read AfterRead (RAR) I: sub r4,r1,r3 J: add r2,r1,r5 •Only RAW effects in pipelining •WAR,WAW,RAR do not effects in pipelining
  • 13.
    Data Hazards 13 This isanother representation of the stall. LW R1, 0(R2) IF ID EX MEM WB SUB R4, R1, R5 IF ID EX MEM WB AND R6, R1, R7 IF ID EX MEM WB OR R8, R1, R9 IF ID EX MEM WB
  • 14.
    Example ADD R3,R4,R5 SUB R1,R2,R3 DIVR1,R2,R3 ST R2,R4 MUL R4,R3,R2 14
  • 15.
    Solution 1. F DE M WB 2. F - - - D E M WB 3. F D E M WB 4. F D E M WB 5. F - - - D E M WB 15
  • 16.
    Example 1.ADD R3,R4,R5 >2 clock cycle 2.SUB R1,R2,R3 > 4 clock cycle 3.DIV R1,R3,R2 > 5 clock cycle 16
  • 17.
    Solution 1. F DE E M WB 2. F - - - - D E E E E M WB 3. - - - - F D - - - E E E E E M WB 17
  • 18.
    Hazards solution Forwarding: To minimizeor remove the stalls Type of instruction: Arithmetic> (add,sub,div,mul) Movement> (load,store,move) 18
  • 19.
    Forwording 19 1.ADD R3,R4,R5 >2 clock cycle 2.SUB R1,R2,R3 > 4 clock cycle 3.DIV R1,R3,R2 > 5 clock cycle 4.LD R2,R1 > 3 clock cycle
  • 20.
    Solution 20 1. F DE E M WB 2. F - - D E E E E M WB 3. F - - - - D E E E E E M WB 4. F - - - - - D E E E M WB
  • 21.