EECC551 - Shaaban #1 Lec # 4 winter 2000 12-12-2000 Data Hazards Requiring Stall Cycles In some code sequence cases, potential data hazards cannot be handled.

Slides:



Advertisements
Similar presentations
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.
Advertisements

CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
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 IF IDEX MEM L.D F4,0(R2) MUL.D F0, F4, F6 ADD.D F2, F0, F8 L.D F2, 0(R2) WB IF IDM1 MEM WBM2M3M4M5M6M7 stall.
COMP381 by M. Hamdi 1 Pipeline Hazards. COMP381 by M. Hamdi 2 Pipeline Hazards Hazards are situations in pipelining where one instruction cannot immediately.
CIS429/529 Winter 2007 Pipelining II- 1 Additional pipelining topics Why pipelining is so hard: exception handling ILP techniques: loop unrolling.
CIS429/529 Winter 2007 Pipelining-1 1 Pipeling RISC/MIPS64 five stage pipeline Basic pipeline performance Pipeline hazards Branch hazards More pipeline.
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Sep 24, 2003 Topic: Pipelining -- Intermediate Concepts (Multicycle Operations;
MIPS64 Instruction Format
Computer Organization and Architecture The CPU Structure.
EECC551 - Shaaban #1 Lec # 2 Winter Instruction Pipelining Review:Instruction Pipelining Review: –MIPS In-Order Single-Issue Integer Pipeline.
Chapter 5 Pipelining and Hazards
1  2004 Morgan Kaufmann Publishers Chapter Six. 2  2004 Morgan Kaufmann Publishers Pipelining The laundry analogy.
©UCB CS 162 Computer Architecture Lecture 3: Pipelining Contd. Instructor: L.N. Bhuyan
Instruction Pipelining Review
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
COMP381 by M. Hamdi 1 Pipelining Control Hazards and Deeper pipelines.
EENG449b/Savvides Lec 4.1 1/22/04 January 22, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG Computer.
DLX Instruction Format
COMP381 by M. Hamdi 1 (Recap) Control Hazards. COMP381 by M. Hamdi 2 Control (Branch) Hazard A: beqz r2, label B: label: P: Problem: The outcome.
ENGS 116 Lecture 61 Pipelining Difficulties and MIPS R4000 Vincent H. Berk October 6, 2008 Reading for today: A.3 – A.4, article: Yeager Reading for Wednesday:
EECC551 - Shaaban #1 Lec # 2 Winter Instruction Pipelining Review Instruction pipelining is CPU implementation technique where multiple.
Appendix A Pipelining: Basic and Intermediate Concepts
Instruction Pipelining Review:
CIS429.S00: Lec12- 1 Miscellaneous pipelining topics Why pipelining is so hard: exception handling Advanced pipelining techniques: loop unrolling.
Instruction Pipelining Review:
EECC551 - Shaaban #1 Lec # 2 Winter DLX Instruction Format 16 bits6 bits5 bits Immediate rdrs1Opcode 6 bits5 bits 11 bits Opcoders1rs2rdfunc.
1 Manchester Mark I, This was the second (the first was a small- scale prototype) machine built at Cambridge. A production version of this computer.
Group 5 Alain J. Percial Paula A. Ortiz Francis X. Ruiz.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
-1.1- PIPELINING 2 nd week. -2- Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM PIPELINING 2 nd week References Pipelining concepts The DLX.
Pipeline Hazard CT101 – Computing Systems. Content Introduction to pipeline hazard Structural Hazard Data Hazard Control Hazard.
Lecture 5: Pipelining Implementation Kai Bu
EEL5708 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Pipelining.
Implementing Precise Interrupts in Pipelined Processors James E. Smith Andrew R.Pleszkun Presented By: Ravikumar Source:
CS 1104 Help Session IV Five Issues in Pipelining Colin Tan, S
Implementing Precise Interrupts in Pipelined Processors James E. Smith Andrew R.Pleszkun Presented By: Shrikant G.
Lecture 4.5 Pipelines – Control Hazards Topics Control Hazards Branch Prediction Misprediction stalls Readings: Appendix C September 2, 2015 CSCE 513 Computer.
Branch Hazards and Static Branch Prediction Techniques
Oct. 18, 2000Machine Organization1 Machine Organization (CS 570) Lecture 4: Pipelining * Jeremy R. Johnson Wed. Oct. 18, 2000 *This lecture was derived.
Appendix A. Pipelining: Basic and Intermediate Concept
HazardsCS510 Computer Architectures Lecture Lecture 7 Pipeline Hazards.
CPE 442 hazards.1 Introduction to Computer Architecture CpE 442 Designing a Pipeline Processor (lect. II)
HazardsCS510 Computer Architectures Lecture Lecture 7 Pipeline Hazards.
11 Pipelining Kosarev Nikolay MIPT Oct, Pipelining Implementation technique whereby multiple instructions are overlapped in execution Each pipeline.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
CSC 4250 Computer Architectures September 22, 2006 Appendix A. Pipelining.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
ECE/CS 552: Pipeline Hazards © Prof. Mikko Lipasti Lecture notes based in part on slides created by Mark Hill, David Wood, Guri Sohi, John Shen and Jim.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Data Hazards Dependent instructions add %g1, %g2, %g3 sub %l1, %g3, %o0 Forwarding helps, but not all hazards can be avoided.
Instruction-Level Parallelism
Computer Organization CS224
Lecture 15: Pipelining: Branching & Complications
Pipelining Wrapup Brief overview of the rest of chapter 3
Morgan Kaufmann Publishers The Processor
Exceptions & Multi-cycle Operations
Pipelining: Advanced ILP
The processor: Pipelining and Branching
Instruction Pipelining Review:
CSC 4250 Computer Architectures
Project Instruction Scheduler Assembler for DLX
Overview What are pipeline hazards? Types of hazards
Control Hazards Branches (conditional, unconditional, call-return)
Lecture 06: Pipelining Implementation
Interrupts and exceptions
CMSC 611: Advanced Computer Architecture
Presentation transcript:

EECC551 - Shaaban #1 Lec # 4 winter Data Hazards Requiring Stall Cycles In some code sequence cases, potential data hazards cannot be handled by bypassing. For example: LW R1, 0 (R2) SUB R4, R1, R5 AND R6, R1, R7 OR R8, R1, R9 The LW (load word) instruction has the data in clock cycle 4 (MEM cycle). The SUB instruction needs the data of R1 in the beginning of that cycle. Hazard prevented by hardware pipeline interlock causing a stall cycle.

EECC551 - Shaaban #2 Lec # 4 winter

EECC551 - Shaaban #3 Lec # 4 winter Hardware Pipeline Interlocks A hardware pipeline interlock detects a data hazard and stalls the pipeline until the hazard is cleared. The CPI for the stalled instruction increases by the length of the stall. For the Previous example, (no stall cycle): LW R1, 0(R1) 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 With Stall Cycle: LW R1, 0(R1) IF ID EX MEM WB SUB R4,R1,R5 IF ID STALL EX MEM WB AND R6,R1,R7 IF STALL ID EX MEM WB OR R8, R1, R9 STALL IF ID EX MEM WB

EECC551 - Shaaban #4 Lec # 4 winter

EECC551 - Shaaban #5 Lec # 4 winter

EECC551 - Shaaban #6 Lec # 4 winter

EECC551 - Shaaban #7 Lec # 4 winter

EECC551 - Shaaban #8 Lec # 4 winter Compiler Instruction Scheduling for Data Hazard Stall Reduction Many types of stalls resulting from data hazards are very frequent. For example: A = B + C produces a stall when loading the second data value (B). Rather than allow the pipeline to stall, the compiler could sometimes schedule the pipeline to avoid stalls. Compiler pipeline or instruction scheduling involves rearranging the code sequence (instruction reordering) to eliminate the hazard.

EECC551 - Shaaban #9 Lec # 4 winter Compiler Instruction Scheduling Example For the code sequence: a = b + c d = e - f Assuming loads have a latency of one clock cycle, the following code or pipeline compiler schedule eliminates stalls: a, b, c, d,e, and f are in memory Scheduled code with no stalls: LW Rb,b LW Rc,c LW Re,e ADD Ra,Rb,Rc LW Rf,f SW a,Ra SUB Rd,Re,Rf SWd,Rd Original code with stalls: LW Rb,b LW Rc,c ADD Ra,Rb,Rc SW a,Ra LW Re,e LW Rf,f SUB Rd,Re,Rf SWd,Rd Stall

EECC551 - Shaaban #10 Lec # 4 winter Control Hazards When a conditional branch is executed it may change the PC and, without any special measures, leads to stalling the pipeline for a number of cycles until the branch condition is known. In current DLX pipeline, the conditional branch is resolved in the MEM stage resulting in three stall cycles as shown below: Branch instruction IF ID EX MEM WB Branch successor IF stall stall IF ID EX MEM WB Branch successor + 1 IF ID EX MEM WB Branch successor + 2 IF ID EX MEM Branch successor + 3 IF ID EX Branch successor + 4 IF ID Branch successor + 5 IF Three clock cycles are wasted for every branch for current DLX pipeline

EECC551 - Shaaban #11 Lec # 4 winter Reducing Branch Stall Cycles Pipeline hardware measures to reduce branch stall cycles: 1- Find out whether a branch is taken earlier in the pipeline. 2- Compute the taken PC earlier in the pipeline. In DLX: –In DLX branch instructions BEQZ, BNEZ, test a register for equality to zero. –This can be completed in the ID cycle by moving the zero test into that cycle. –Both PCs (taken and not taken) must be computed early. –Requires an additional adder because the current ALU is not useable until EX cycle. –This results in just a single cycle stall on branches.

EECC551 - Shaaban #12 Lec # 4 winter Modified DLX Pipeline: Conditional Branches Conditional Branches Completed in ID Stage Completed in ID Stage

EECC551 - Shaaban #13 Lec # 4 winter Compile-Time Reduction of Branch Penalties One scheme discussed earlier is to flush or freeze the pipeline by whenever a conditional branch is decoded by holding or deleting any instructions in the pipeline until the branch destination is known (zero pipeline registers, control lines)). Another method is to predict that the branch is not taken where the state of the machine is not changed until the branch outcome is definitely known. Execution here continues with the next instruction; stall occurs here when the branch is taken. Another method is to predict that the branch is taken and begin fetching and executing at the target; stall occurs here if the branch is not taken

EECC551 - Shaaban #14 Lec # 4 winter Predict Branch Not-Taken Scheme

EECC551 - Shaaban #15 Lec # 4 winter Static Compiler Branch Prediction Two basic methods exist to statically predict branches at compile time: 1By examination of program behavior and the use of information collected from earlier runs of the program. –For example, a program profile may show that most forward branches and backward branches (often forming loops) are taken. The simplest scheme in this case is to just predict the branch as taken. 2To predict branches on the basis of branch direction, choosing backward branches as taken and forward branches as not taken.

EECC551 - Shaaban #16 Lec # 4 winter

EECC551 - Shaaban #17 Lec # 4 winter Profile-Based Compiler Branch Misprediction Rates

EECC551 - Shaaban #18 Lec # 4 winter

EECC551 - Shaaban #19 Lec # 4 winter Reduction of Branch Penalties: Delayed Branch When delayed branch is used, the branch is delayed by n cycles, following this execution pattern: conditional branch instruction sequential successor 1 sequential successor 2 …….. sequential successor n branch target if taken The sequential successor instruction are said to be in the branch delay slots. These instructions are executed whether or not the branch is taken. In Practice, all machines that utilize delayed branching have a single instruction delay slot. The job of the compiler is to make the successor instructions valid and useful instructions.

EECC551 - Shaaban #20 Lec # 4 winter Delayed Branch Example

EECC551 - Shaaban #21 Lec # 4 winter Delayed Branch-delay Slot Scheduling Strategies The branch-delay slot instruction can be chosen from three cases: A An independent instruction from before the branch: Always improves performance when used. The branch must not depend on the rescheduled instruction. B An instruction from the target of the branch: Improves performance if the branch is taken and may require instruction duplication. This instruction must be safe to execute if the branch is not taken. C An instruction from the fall through instruction stream: Improves performance when the branch is not taken. The instruction must be safe to execute when the branch is taken. The performance and usability of cases B, C is improved by using a canceling or nullifying branch.

EECC551 - Shaaban #22 Lec # 4 winter (A)(B)(C)

EECC551 - Shaaban #23 Lec # 4 winter Branch-delay Slot: Canceling Branches In a canceling branch, a static compiler branch direction prediction is included with the branch-delay slot instruction. When the branch goes as predicted, the instruction in the branch delay slot is executed normally. When the branch does not go as predicted the instruction is turned into a no-op. Canceling branches eliminate the conditions on instruction selection in delay instruction strategies B, C The effectiveness of this method depends on whether we predict the branch correctly.

EECC551 - Shaaban #24 Lec # 4 winter

EECC551 - Shaaban #25 Lec # 4 winter DLX Performance Using Canceling Delay Branches

EECC551 - Shaaban #26 Lec # 4 winter Performance of Branch Schemes The effective pipeline speedup with branch penalties: (assuming an ideal pipeline CPI of 1) Pipeline speedup = Pipeline depth 1 + Pipeline stall cycles from branches Pipeline stall cycles from branches = Branch frequency X branch penalty Pipeline speedup = Pipeline Depth 1 + Branch frequency X Branch penalty

EECC551 - Shaaban #27 Lec # 4 winter Pipeline Performance Example Assume the following DLX instruction mix: What is the resulting CPI for the pipelined DLX with forwarding and branch address calculation in ID stage when using a branch not-taken scheme? CPI = Ideal CPI + Pipeline stall clock cycles per instruction = 1 + stalls by loads + stalls by branches = x.25 x x.45 x 1 = = TypeFrequency Arith/Logic40% Load30% of which 25% are followed immediately by an instruction using the loaded value Store10% branch20% of which 45% are taken

EECC551 - Shaaban #28 Lec # 4 winter Branch Penalty Example For a pipeline similar to the MIPS R4000, it takes three pipeline stages before the branch target address is known and an additional cycle before the branch condition is evaluated. Assuming no stalls on the registers in the conditional comparison. The branch penalty for the three simplest branch prediction schemes: Branch Scheme Penalty unconditional Penalty untaken Penalty taken Flush pipeline Predict taken Predict untaken

EECC551 - Shaaban #29 Lec # 4 winter Pipelining and Handling of Exceptions Exceptions are events that usually occur in normal program execution where the normal execution order of the instructions is changed (often called: interrupts, faults). Types of exceptions include: I/O device request Invoking an operating system service Tracing instruction execution Breakpoint (programmer-requested interrupt). Integer overflow or underflow FP anomaly Page fault (not in main memory) Misaligned memory access Memory protection violation Undefined instruction Hardware malfunctions

EECC551 - Shaaban #30 Lec # 4 winter Exception eventIBM 360VAXMotorola 680x0Intel 80x86 I/O device requestInput/output interruption Device interruptException (Level autovector) Vectored interrupt Tracing instruction execution Not applicableException (trace fault) Exception (trace)Interrupt (single- step trap) Invoking the operat- ing system service from a user program Supervisor call interruption Exception (change mode supervisor trap) Exception (unimplemented instruction)--- on Macintosh Interrupt (INT instruction) Page fault (not in main memory) Not applicable (only in 370) Exception (transla- tion not valid fault) Exception (memory- management unit errors) Interrupt (page fault) Misaligned memory accesses Program interrup- tion (specification exception) Not applicableException (address error) Not applicable Using undefined instructions Program interrup- tion (operation exception) Exception (opcode privileged/ reserved fault) Exception (illegal instruction or break- point/unimplemented instruction) Interrupt (invalid opcode) Hardware malfunctions Machine-check interruption Exception (machine-check abort) Exception (bus error) Not applicable BreakpointNot applicableException (break- point fault) Exception (illegal instruction or break- point) Interrupt (break- point trap) Integer arithmetic overflow or under- flow; FP trap Program interrup- tion (overflow or underflow exception) Exception (integer overflow trap or floating underflow fault) Exception (floating-point coprocessor errors) Interrupt (overflow trap or math unit exception) Memory protection violations Program interrup- tion (protection exception) Exception (access control violation fault) Exception (bus error) Interrupt (protection exception) Power failureMachine-check interruption Urgent interruptNot applicableNonmaskable interrupt The names of common exceptions vary across four different architectures.

EECC551 - Shaaban #31 Lec # 4 winter Characteristics of Exceptions Synchronous vs. asynchronous: Synchronous: occurs at the same place with the same data and memory allocation Asynchronous: Caused by devices external to the processor and memory. User requested vs. coerced: User requested: The user task requests the event. Coerced: Caused by some hardware event. User maskable vs. user nonmaskable: User maskable: Can be disabled by the user task using a mask. Within vs. between instructions: Whether it prevents instruction completion by happening in the middle of execution. Resuming vs. terminating: Terminating: The program execution always stops after the event. Resuming: the program continues after the event. The state of the pipeline must be saved to handle this type of exception. The pipeline is restartable in this case.

EECC551 - Shaaban #32 Lec # 4 winter Handling of Resuming Exceptions A resuming exception (e.g. a virtual memory page fault) usually requires the intervention of the operating system. The pipeline must be safely shut down and its state saved for the execution to resume after the exception is handled as follows: 1Force a trap instruction into the pipeline on the next IF. 2Turn of all writes for the faulting instruction and all instructions in the pipeline. Place zeroes into pipeline latches starting with the instruction that caused the fault to prevent state changes. 3The execution handling routine of the operating system saves the PC of the faulting instruction and other state data to be used to return from the exception.

EECC551 - Shaaban #33 Lec # 4 winter Exception Handling Issues When using delayed branches,as many PCs as the the length of the branch delay plus one need to be saved and restored to restore the state of the machine. After the exception has been handled special instructions are needed to return the machine to the state before the exception occurred (RFE, Return to User code in DLX). Precise exceptions imply that a pipeline is stopped so the instructions just before the faulting instruction are completed and and those after it can be restarted from scratch. Machines with arithmetic trap handlers and demand paging must support precise exceptions.

EECC551 - Shaaban #34 Lec # 4 winter Exceptions in DLX The following represent problem exceptions for the DLX pipeline stages: IF Page fault on instruction fetch; misaligned memory access; memory-protection violation. ID Undefined or illegal opcode EX Arithmetic exception MEM Page fault on data fetch; misaligned memory access; memory-protection violation WB None Example: LW IF ID EX MEM WB ADD IF ID EX MEM WB can cause a data page fault and an arithmetic exception at the same time ( LW in MEM and ADD in EX) Handled by dealing with data page fault and then restarting execution, then the second exception will occur but not the first.

EECC551 - Shaaban #35 Lec # 4 winter Precise Exception Handling in DLX The instruction pipeline is required to handle exceptions of instruction i before those of instruction i+1 The hardware posts all exceptions caused by an instruction in a status vector associated with the instruction which is carried along with the instruction as it goes through the pipeline. Once an exception indication is set in the vector, any control signals that cause a data value write is turned off. When an instruction enters WB the vector is checked, if any exceptions are posted, they are handled in the order they would be handled in an unpipelined machine. Any action taken in earlier pipeline stages is invalid but cannot change the state of the machine since writes where disabled.