Pipeline Hazards Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See P&H Appendix 4.7.

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers The Processor
Advertisements

1 Pipelining Part 2 CS Data Hazards Data hazards occur when the pipeline changes the order of read/write accesses to operands that differs from.
CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
Pipeline Computer Organization II 1 Hazards Situations that prevent starting the next instruction in the next cycle Structural hazards – A required resource.
Lecture Objectives: 1)Define pipelining 2)Calculate the speedup achieved by pipelining for a given number of instructions. 3)Define how pipelining improves.
Review: Pipelining. Pipelining Laundry Example Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold Washer takes 30 minutes Dryer.
1 RISC Pipeline Han Wang CS3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 4.6.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Pipeline Hazards See: P&H Chapter 4.7.
Pipeline Control Hazards and Instruction Variations Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See P&H Appendix 4.8 &
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University RISC Pipeline See: P&H Chapter 4.6.
Pipeline Control Hazards and Instruction Variations Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See P&H Appendix 4.8 &
Review: MIPS Pipeline Data and Control Paths
Pipelining III Andreas Klappenecker CPSC321 Computer Architecture.
1  2004 Morgan Kaufmann Publishers Chapter Six. 2  2004 Morgan Kaufmann Publishers Pipelining The laundry analogy.
1 Stalling  The easiest solution is to stall the pipeline  We could delay the AND instruction by introducing a one-cycle delay into the pipeline, sometimes.
L17 – Pipeline Issues 1 Comp 411 – Fall /1308 CPU Pipelining Issues Finishing up Chapter 6 This pipe stuff makes my head hurt! What have you been.
Lec 9: Pipelining Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University.
Morgan Kaufmann Publishers Dr. Zhao Zhang Iowa State University
Computer Architecture - A Pipelined Datapath A Pipelined Datapath  Resisters are used to save data between stages. 1/14.
1  1998 Morgan Kaufmann Publishers Chapter Six Enhancing Performance with Pipelining.
ENGS 116 Lecture 51 Pipelining and Hazards Vincent H. Berk September 30, 2005 Reading for today: Chapter A.1 – A.3, article: Patterson&Ditzel Reading for.
Pipeline Hazard CT101 – Computing Systems. Content Introduction to pipeline hazard Structural Hazard Data Hazard Control Hazard.
1 Pipelining Reconsider the data path we just did Each instruction takes from 3 to 5 clock cycles However, there are parts of hardware that are idle many.
Automobile Manufacturing 1. Build frame. 60 min. 2. Add engine. 50 min. 3. Build body. 80 min. 4. Paint. 40 min. 5. Finish.45 min. 275 min. Latency: Time.
Comp Sci pipelining 1 Ch. 13 Pipelining. Comp Sci pipelining 2 Pipelining.
MIPS Pipeline Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See P&H Chapter 4.6.
CMPE 421 Parallel Computer Architecture
CS 1104 Help Session IV Five Issues in Pipelining Colin Tan, S
Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University MIPS Pipeline See P&H Chapter 4.6.
Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University MIPS Pipeline See P&H Chapter 4.6.
CSE431 L06 Basic MIPS Pipelining.1Irwin, PSU, 2005 MIPS Pipeline Datapath Modifications  What do we need to add/modify in our MIPS datapath? l State registers.
10/11: Lecture Topics Execution cycle Introduction to pipelining
Introduction to Computer Organization Pipelining.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
L17 – Pipeline Issues 1 Comp 411 – Fall /23/09 CPU Pipelining Issues Read Chapter This pipe stuff makes my head hurt! What have you been.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
EECS 322 April 10, 2000 EECS 322 Computer Architecture Pipeline Control, Data Hazards and Branch Hazards.
CSE 340 Computer Architecture Spring 2016 Overcoming Data Hazards.
Pipeline Control Hazards Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix 4.8.
Stalling delays the entire pipeline
CSCI206 - Computer Organization & Programming
Pipeline Hazards Hakim Weatherspoon CS 3410, Spring 2012
Pipeline Control Hazards and Instruction Variations
Pipeline Control Hazards
5 Steps of MIPS Datapath Figure A.2, Page A-8
Single Clock Datapath With Control
CDA 3101 Spring 2016 Introduction to Computer Organization
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Chapter 4 The Processor Part 3
Review: MIPS Pipeline Data and Control Paths
Morgan Kaufmann Publishers The Processor
Pipelining review.
Pipeline Hazards Hakim Weatherspoon CS 3410, Spring 2013
Computer Organization CS224
Data and Control Hazards
Pipeline Control Hazards and Instruction Variations
Pipelining in more detail
CSCI206 - Computer Organization & Programming
CSCI206 - Computer Organization & Programming
Data Hazards Data Hazard
Pipeline control unit (highly abstracted)
The Processor Lecture 3.6: Control Hazards
The Processor Lecture 3.5: Data Hazards
Pipeline control unit (highly abstracted)
Pipeline Control unit (highly abstracted)
Pipelining Hakim Weatherspoon CS 3410 Computer Science
Pipelining Hakim Weatherspoon CS 3410 Computer Science
MIPS Pipeline Hakim Weatherspoon CS 3410, Spring 2013 Computer Science
Pipelining Hazards.
Presentation transcript:

Pipeline Hazards Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See P&H Appendix 4.7

2 Announcements PA1 available: mini-MIPS processor PA1 due next Friday Work in pairs Use your resources FAQ, class notes, book, Sections, office hours, newsgroup, CSUGLab HW1 graded Max: 10; Median: 9; Mean: 8.3; Stddev: 1.8 Great job! Regrade policy –Submit written request to lead TA, lead TA will pick a different grader –Submit another written request, lead TA will regrade directly –Submit yet another written request for professor to regrade.

3 Announcements Prelims: Thursday, March 10 th in class Thursday, April 28 th Evening Late Policy 1) Each person has a total of four “slip days” 2) For projects, slip days are deducted from all partners 3) 10% deducted per day late after slip days are exhausted

4 Goals for Today Data Hazards Data dependencies Problem, detection, and solutions –(delaying, stalling, forwarding, bypass, etc) Forwarding unit Hazard detection unit Next time Control Hazards What is the next instruction to execute if a branch is taken? Not taken?

5 Broken Example IF ID MEM WB IF ID MEMWB IF ID MEMWB IF ID MEMWB IF ID MEM WB Clock cycle sub r5, r3, r4 lw r6, 4(r3) or r5, r3, r5 sw r6, 12(r3) add r3, r1, r2

6 What Can Go Wrong? Data Hazards register file reads occur in stage 2 (ID) register file writes occur in stage 5 (WB) next instructions may read values about to be written How to detect? Logic in ID stage: stall = (ID.rA != 0 && (ID.rA == EX.rD || ID.rA == M.rD || ID.rA == WB.rD)) || (same for rB)

7 IF/ID +4 ID/EXEX/MEMMEM/WB mem d in d out addr inst PC+4 OP B A Rd B D M D PC+4 imm OP Rd OP Rd PC inst mem Rd RaRb D B A detect hazard Detecting Data Hazards add r3, r1, r2 sub r5, r3, r5 or r6, r3, r4 add r6, r3, r8

8 Resolving Data Hazards What to do if data hazard detected?

9 Stalling Clock cycle add r3, r1, r2 sub r5, r3, r5 or r6, r3, r4 add r6, r3, r8

10 Forwarding Datapath data mem B A B D M D inst mem D rD B A Rd WE Op WE Op rA rB PC +4 Op nop inst /stall

11 Stalling How to stall an instruction in ID stage prevent IF/ID pipeline register update –stalls the ID stage instruction convert ID stage instr into nop for later stages –innocuous “bubble” passes through pipeline prevent PC update –stalls the next (IF stage) instruction

12 Forwarding Clock cycle add r3, r1, r2 sub r5, r3, r5 or r6, r3, r4 add r6, r3, r8

13 Forwarding Clock cycle add r3, r1, r2 sub r5, r3, r4 lw r6, 4(r3) or r5, r3, r5 sw r6, 12(r3)

14 Forwarding Forward correct value from? 1.ALU output: too late in cycle? 2.EX/MEM.D pipeline register (output from ALU) 3.WB data value (output from ALU or memory) 4.MEM output: too late in cycle, on critical path to? a)ID (just after register file) –maybe pointless? b)EX, just after ID/EX.A and ID/EX.B are read c)MEM, just after EX/MEM.B is read: on critical path data mem B A B D M D inst mem D B A

15 Forwarding Path 1 add r4, r1, r2 nop sub r6, r4, r1 data mem inst mem D B A

16 WB to EX Bypass EX needs value being written by WB Resolve: Add bypass from WB final value to start of EX Detect:

17 Forwarding Path 2 add r4, r1, r2 sub r6, r4, r1 data mem inst mem D B A

18 MEM to EX Bypass EX needs ALU result that is still in MEM stage Resolve: Add a bypass from EX/MEM.D to start of EX Detect:

19 Forwarding Datapath data mem B A B D M D inst mem D B A Rd Rb WE MC Ra MC

20 Tricky Example data mem inst mem D B A add r1, r1, r2 SUB r1, r1, r3 OR r1, r4, r1

21 More Data Hazards add r4, r1, r2 nop sub r6, r4, r1 data mem inst mem D B A

22 Register File Bypass Reading a value that is currently being written Detect: ((Ra == MEM/WB.Rd) or (Rb == MEM/WB.Rd)) and (WB is writing a register) Resolve: Add a bypass around register file (WB to ID) Better: (Hack) just negate register file clock –writes happen at end of first half of each clock cycle –reads happen during second half of each clock cycle

23 Quiz Find all hazards, and say how they are resolved: add r3, r1, r2 sub r3, r2, r1 nand r4, r3, r1 or r0, r3, r4 xor r1, r4, r3 sb r4, 1(r0)

24 Memory Load Data Hazard lw r4, 20(r8) sub r6, r4, r1 data mem inst mem D B A

25 Resolving Memory Load Hazard Load Data Hazard Value not available until WB stage So: next instruction can’t proceed if hazard detected Resolution: MIPS 2000/3000: one delay slot –ISA says results of loads are not available until one cycle later –Assembler inserts nop, or reorders to fill delay slot MIPS 4000 onwards: stall –But really, programmer/compiler reorders to avoid stalling in the load delay slot

26 Quiz 2 add r3, r1, r2 nand r5, r3, r4 add r2, r6, r3 lw r6, 24(r3) sw r6, 12(r2)

27 Data Hazard Recap Delay Slot(s) Modify ISA to match implementation Stall Pause current and all subsequent instructions Forward/Bypass Try to steal correct value from elsewhere in pipeline Otherwise, fall back to stalling or require a delay slot Tradeoffs?

28 More Hazards beq r1, r2, L add r3, r0, r3 sub r5, r4, r6 L: or r3, r2, r4 data mem inst mem D B A PC +4

29 More Hazards beq r1, r2, L add r3, r0, r3 sub r5, r4, r6 L: or r3, r2, r4 data mem inst mem D B A PC +4

30 Control Hazards instructions are fetched in stage 1 (IF) branch and jump decisions occur in stage 3 (EX) i.e. next PC is not known until 2 cycles after branch/jump Delay Slot ISA says N instructions after branch/jump always executed –MIPS has 1 branch delay slot Stall (+ Zap) prevent PC update clear IF/ID pipeline register –instruction just fetched might be wrong one, so convert to nop allow branch to continue into EX stage

31 Delay Slot beq r1, r2, L ori r2, r0, 1 L: or r3, r1, r4 data mem inst mem D B A PC +4 branch calc decide branch

32 Control Hazards: Speculative Execution Control Hazards instructions are fetched in stage 1 (IF) branch and jump decisions occur in stage 3 (EX) i.e. next PC not known until 2 cycles after branch/jump Stall Delay Slot Speculative Execution Guess direction of the branch –Allow instructions to move through pipeline –Zap them later if wrong guess Useful for long pipelines

33 Loops

34 Branch Prediction

35 Pipelining: What Could Possibly Go Wrong? Data hazards register file reads occur in stage 2 (IF) register file writes occur in stage 5 (WB) next instructions may read values soon to be written Control hazards branch instruction may change the PC in stage 3 (EX) next instructions have already started executing Structural hazards resource contention so far: impossible because of ISA and pipeline design