pipelining hazards
play

PIPELINING: HAZARDS Mahdi Nazm Bojnordi Assistant Professor School - PowerPoint PPT Presentation

PIPELINING: HAZARDS Mahdi Nazm Bojnordi Assistant Professor School of Computing University of Utah CS/ECE 6810: Computer Architecture Overview Announcement Homework 1 submission deadline: Jan. 30 th This lecture Impacts of


  1. PIPELINING: HAZARDS Mahdi Nazm Bojnordi Assistant Professor School of Computing University of Utah CS/ECE 6810: Computer Architecture

  2. Overview ¨ Announcement ¤ Homework 1 submission deadline: Jan. 30 th ¨ This lecture ¤ Impacts of pipelining on performance ¤ The MIPS five-stage pipeline ¤ Pipeline hazards n Structural hazards n Data hazards

  3. Pipelining Technique ¨ Improving throughput at the expense of latency ¤ Delay: D = T + n δ ¤ Throughput: IPS = n/(T + n δ ) Combinational Logic D = Critical Path Delay = 30 IPS = Combinational Logic Combinational Logic D = IPS = Critical Path Delay = 15 Critical Path Delay = 15 D = Comb. Logic Comb. Logic Comb. Logic IPS = Delay = 10 Delay = 10 Delay = 10

  4. Pipelining Technique ¨ Improving throughput at the expense of latency ¤ Delay: D = T + n δ ¤ Throughput: IPS = n/(T + n δ ) Combinational Logic D = 31 Critical Path Delay = 30 IPS = 1/31 Combinational Logic Combinational Logic D = 32 IPS = 2/32 Critical Path Delay = 15 Critical Path Delay = 15 D = 33 Comb. Logic Comb. Logic Comb. Logic IPS = 3/33 Delay = 10 Delay = 10 Delay = 10

  5. Pipelining Latency vs. Throughput ¨ Theoretical delay and throughput models for perfect pipelining Delay (D) Throughput (IPS) 20 Relative Performance 15 10 5 0 0 50 100 150 200 Number of Pipeline Stages

  6. Five Stage MIPS Pipeline

  7. Simple Five Stage Pipeline ¨ A pipelined load-store architecture that processes up to one instruction per cycle Write Back PC Inst. Register Data ALU Memory File Memory Inst. Fetch Inst. Decode Execute Memory

  8. Instruction Fetch ¨ Read an instruction from memory (I-Cache) ¤ Use the program counter (PC) to index into the I- Memory ¤ Compute NPC by incrementing current PC n What about branches? ¨ Update pipeline registers ¤ Write the instruction into the pipeline registers

  9. Instruction Fetch clock Branch Target NPC = PC + 4 NPC clock PC + Why increment 4 by 4? Instruction Memory Pipeline Register

  10. Instruction Fetch clock P3 Branch Target NPC = PC + 4 NPC clock PC + P2 Why increment 4 by 4? Instruction P1 Memory Critical Path = Max{P1, P2, P3} Pipeline Register

  11. Instruction Decode ¨ Generate control signals for the opcode bits ¨ Read source operands from the register file (RF) ¤ Use the specifiers for indexing RF n How many read ports are required? ¨ Update pipeline registers ¤ Send the operand and immediate values to next stage ¤ Pass control signals and NPC to next stage

  12. Instruction Decode target NPC NPC reg Register Instruction File reg ctrl decode Pipeline Pipeline Register Register

  13. Execute Stage ¨ Perform ALU operation ¤ Compute the result of ALU n Operation type: control signals n First operand: contents of a register n Second operand: either a register or the immediate value ¤ Compute branch target n Target = NPC + immediate ¨ Update pipeline registers ¤ Control signals, branch target, ALU results, and destination

  14. Execute Stage Target NPC + Res reg ALU reg reg ctrl ctrl Pipeline Pipeline Register Register

  15. Memory Access ¨ Access data memory ¤ Load/store address: ALU outcome ¤ Control signals determine read or write access ¨ Update pipeline registers ¤ ALU results from execute ¤ Loaded data from D-Memory ¤ Destination register

  16. Memory Access Target Res Res addr Dat reg Memory data data ctrl ctrl Pipeline Pipeline Register Register

  17. Register Write Back ¨ Update register file ¤ Control signals determine if a register write is needed ¤ Only one write port is required n Write the ALU result to the destination register, or n Write the loaded data into the register file

  18. Five Stage Pipeline ¨ Ideal pipeline: IPC=1 ¤ Is there enough resources to keep the pipeline stages busy all the time? Inst. Fetch Decode Execute Memory Writeback + + PC ALU Reg. Reg. 4 File File Mem Mem

  19. Pipeline Hazards

  20. Pipeline Hazards ¨ Structural hazards: multiple instructions compete for the same resource ¨ Data hazards: a dependent instruction cannot proceed because it needs a value that hasn’t been produced ¨ Control hazards: the next instruction cannot be fetched because the outcome of an earlier branch is unknown

  21. Structural Hazards ¨ 1. Unified memory for instruction and data R1 ß Mem[R2] R3 ß Mem[R20] R6 ß R4-R5 R7 ß R1+R0

  22. Structural Hazards ¨ 1. Unified memory for instruction and data R1 ß Mem[R2] R3 ß Mem[R20] R6 ß R4-R5 R7 ß R1+R0 Separate inst. and data memories.

  23. Structural Hazards ¨ 1. Unified memory for instruction and data ¨ 2. Register file with shared read/write access ports R1 ß Mem[R2] R3 ß Mem[R20] R6 ß R4-R5 R7 ß R1+R0

  24. Structural Hazards ¨ 1. Unified memory for instruction and data ¨ 2. Register file with shared read/write access ports R1 ß Mem[R2] R3 ß Mem[R20] R6 ß R4-R5 R7 ß R1+R0 Register access in half cycles.

  25. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Loading data from memory. R1 ß Mem[R2] R3 ß R1+R0 R4 ß R1-R3

  26. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Loaded data will be available two cycles later. R1 ß Mem[R2] R3 ß R1+R0 R4 ß R1-R3

  27. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Inserting two bubbles. R1 ß Mem[R2] Nothing Nothing R3 ß R1+R0 R4 ß R1-R3

  28. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Inserting single bubble + RF bypassing. R1 ß Mem[R2] Nothing R3 ß R1+R0 R4 ß R1-R3 Load delay slot. SW vs. HW management?

  29. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Using the result of an ALU instruction. R1 ß R2+R3 R5 ß R1+R0 R3 ß R1+R0 R4 ß R1-R3

  30. Data Hazards ¨ True dependence: read-after-write (RAW) ¤ Consumer has to wait for producer Using the result of an ALU instruction. R1 ß R2+R3 R5 ß R1+R0 R3 ß R1+R0 R4 ß R1-R3 Forwarding ALU result.

  31. Data Hazards ¨ True dependence: read-after-write (RAW) ¨ Anti dependence: write-after-read (WAR) ¤ Write must wait for earlier read R1 ß R2+R1 R2 ß R8+R9

  32. Data Hazards ¨ True dependence: read-after-write (RAW) ¨ Anti dependence: write-after-read (WAR) ¤ Write must wait for earlier read R1 ß R2+R1 R2 ß R8+R9 No WAR hazards in 5-stage pipeline!

  33. Data Hazards ¨ True dependence: read-after-write (RAW) ¨ Anti dependence: write-after-read (WAR) ¨ Output dependence: write-after-write (WAW) ¤ Old writes must not overwrite the younger write R1 ß R2+R3 R1 ß R8+R9

  34. Data Hazards ¨ True dependence: read-after-write (RAW) ¨ Anti dependence: write-after-read (WAR) ¨ Output dependence: write-after-write (WAW) ¤ Old writes must not overwrite the younger write R1 ß R2+R3 R1 ß R8+R9 No WAW hazards in 5-stage pipeline!

  35. Data Hazards ¨ Forwarding with additional hardware

  36. Data Hazards ¨ How to detect and resolve data hazards ¤ Show all of the data hazards in the code below R1 ß Mem[R2] R2 ß R1+R0 R1 ß R1-R2 Mem[R3] ß R2

  37. Data Hazards ¨ How to detect and resolve data hazards ¤ Show all of the data hazards in the code below R1 ß Mem[R2] WAR R2 ß R1+R0 WAW RAW R1 ß R1-R2 Mem[R3] ß R2

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend