Pipelining in Computer Architecture

carnegie mellon n.w
1 / 72
Embed
Share

Explore the principles of pipelining, challenges in creating pipelined processors, and real-world examples like the Ford Model T assembly line. Learn about computational examples, 3-way pipelining, pipeline diagrams, and operating a pipeline efficiently. Discover the limitations of pipelining due to nonuniform delays.

  • Pipelining
  • Computer Architecture
  • Processor
  • Ford Model T
  • Pipeline Efficiency

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Carnegie Mellon Y86-64 Processor Architecture: Pipelined Implementation COMP 222: Introduction to Computer Organization Instructor: Alan L. Cox CS:APP3e 1

  2. Overview General Principles of Pipelining Goal Difficulties Creating a Pipelined Y86-64 Processor Rearranging SEQ Inserting pipeline registers Problems with data and control hazards CS:APP3e 2

  3. Real-World Pipelines: Ford Model T Moving Assembly Line Idea Divide process into independent stages Move objects through stages in sequence At any given times, multiple objects being processed CS:APP3e 3

  4. Computational Example 300 ps 20 ps R e g Delay = 320 ps Throughput = 3.12 GIPS Combinational logic Clock System Computation requires total of 300 picoseconds Additional 20 picoseconds to save result in register Must have clock cycle of at least 320 ps CS:APP3e 4

  5. 3-Way Pipelined Version 100 ps 20 ps 100 ps 20 ps 100 ps 20 ps Comb. logic A R e g Comb. logic B R e g Comb. logic C R e g Delay = 360 ps Throughput = 8.33 GIPS Clock System Divide combinational logic into 3 blocks of 100 ps each Can begin new operation as soon as previous one passes through stage A. Begin new operation every 120 ps Overall latency increases 360 ps from start to finish CS:APP3e 5

  6. Pipeline Diagrams Unpipelined OP1 OP2 OP3 Time Cannot start new operation until previous one completes 3-Way Pipelined A B A C B A OP1 OP2 OP3 C B C Time Up to 3 operations in process simultaneously CS:APP3e 6

  7. Operating a Pipeline 239 241 300 359 Clock OP1 OP2 OP3 A B A C B A C B C 0 120 240 360 480 640 Time 100 ps 100 ps 100 ps 100 ps 20 ps 20 ps 20 ps 20 ps 100 ps 100 ps 100 ps 100 ps 20 ps 20 ps 20 ps 20 ps 100 ps 100 ps 100 ps 100 ps 20 ps 20 ps 20 ps 20 ps Comb. Comb. Comb. Comb. Comb. Comb. Comb. logic A A A A Comb. logic B B B B Comb. logic C C C C Comb. logic logic logic Comb. logic logic logic Comb. logic logic logic R R R R R e g g g g R e g g g g R e g g g g R e e e R e e e R R R e e e Clock Clock Clock Clock CS:APP3e 7

  8. Limitations: Nonuniform Delays 50 ps 20 ps 150 ps 20 ps 100 ps 20 ps R e g Comb. logic B R e g Comb. logic C R e g Comb. logic A Delay = 510 ps Throughput = 5.88 GIPS Clock OP1 OP2 OP3 A B C A B C A B C Time Throughput limited by slowest stage Other stages sit idle for much of the time Challenging to partition system into balanced stages CS:APP3e 8

  9. Limitations: Register Overhead 50 ps 20 ps 50 ps 20 ps 50 ps 20 ps 50 ps 20 ps 50 ps 20 ps 50 ps 20 ps R e g R e g R e g R e g R e g R e g Comb. logic Comb. logic Comb. logic Comb. logic Comb. logic Comb. logic Clock Delay = 420 ps, Throughput = 14.29 GIPS As try to deepen pipeline, overhead of loading registers becomes more significant Percentage of clock cycle spent loading register: 1-stage pipeline: 6.25% 3-stage pipeline: 16.67% 6-stage pipeline: 28.57% High speeds of modern processor designs obtained through very deep pipelining CS:APP3e 9

  10. Data Dependencies R e g Combinational logic Clock OP1 OP2 OP3 Time System Each operation depends on result from preceding one CS:APP3e 10

  11. Data Hazards Comb. logic A R e g Comb. logic B R e g Comb. logic C R e g Clock OP1 OP2 OP3 OP4 A B A C B A C B A C B C Time Result does not feed back around in time for next operation Pipelining has changed behavior of system CS:APP3e 11

  12. Data Dependencies in Processors 1 irmovq $50, %rax 2 addq %rax , %rbx 3 mrmovq 100( %rbx ), %rdx Result from one instruction used as operand for another Read-after-write (RAW) dependency Very common in actual programs Must make sure our pipeline handles these properly Get correct results Minimize performance impact CS:APP3e 12

  13. SEQ Hardware Stages occur in sequence One operation in process at a time CS:APP3e 13

  14. SEQ+ Hardware Still sequential implementation Reorder PC stage to put at beginning PC Stage Task is to select PC for current instruction Based on results computed by previous instruction Processor State PC is no longer stored in register But, can determine PC based on other stored information CS:APP3e 14

  15. Adding Pipeline Registers newPC PC valE, valM Write back valM Data Data memory memory Memory Addr, Data valE CC CC ALU ALU Execute Cnd aluA, aluB valA, valB srcA, srcB dstA, dstB Decode A A B B M M Register Register Register Register file file file file E E icode, ifun rA , rB valP valC Instruction PC PC Instruction memory memory increment increment Fetch PC CS:APP3e 15

  16. Pipeline Stages Fetch Select current PC Read instruction Compute incremented PC Decode Read program registers Execute Operate ALU Memory Read or write data memory Write Back Update register file CS:APP3e 16

  17. PIPE- Hardware Pipeline registers hold intermediate values from instruction execution Forward (Upward) Paths Values passed from one stage to next Cannot jump past stages e.g., valC passes through decode CS:APP3e 17

  18. Signal Naming Conventions S_Field Value of Field held in stage S pipeline register s_Field Value of Field computed in stage S CS:APP3e 18

  19. Feedback Paths Predicted PC Guess value of next PC Branch information Jump taken/not-taken Fall-through or target address Return point Read from memory Register updates To register file write ports CS:APP3e 19

  20. Predicting the PC Start fetch of new instruction after current one has completed fetch stage Not enough time to reliably determine next instruction Guess which instruction will follow Recover if prediction was incorrect CS:APP3e 20

  21. Our Prediction Strategy Instructions that Don t Transfer Control Predict next PC to be valP Always reliable Call and Unconditional Jumps Predict next PC to be valC (destination) Always reliable Conditional Jumps Predict next PC to be valC (destination) Only correct if branch is taken Typically right 60% of time Return Instruction Don t try to predict CS:APP3e 21

  22. Recovering from PC Misprediction Mispredicted Jump Will see branch condition flag once instruction reaches memory stage Can get fall-through PC from valA (value M_valA) Return Instruction Will get return PC when ret reaches write-back stage (W_valM) CS:APP3e 22

  23. Pipeline Demonstration 1 2 3 4 5 6 7 8 9 F D F E D F M E D F W irmovq $1,%rax #I1 M E D F W M E D irmovq $2,%rcx #I2 W M E irmovq $3,%rdx #I3 W M irmovq $4,%rbx #I4 W halt #I5 Cycle 5 W I1 M I2 E I3 D I4 F I5 File: demo-basic.ys CS:APP3e 23

  24. Data Dependencies: 3 Nops 1 2 3 4 5 6 7 8 9 10 11 # demo-h3.ys F F D D F F E E D D F F M M E E D D F F W W M M E E D D F F 0x000: irmovq $10,%rdx W W M M E E D D F F 0x00a: irmovq $3,%rax W W M M E E D D F F 0x014: nop W W M M E E D D 0x015: nop W W M M E E 0x016: nop W W M M 0x017: addq %rdx,%rax W W 0x019: halt Cycle 6 W W R[%rax] 3 R[%rax] 3 Cycle 7 D D valA R[%rdx] = 10 valB R[%rax] = 3 valB R[%rax] = 3 valA R[%rdx] = 10 CS:APP3e 24

  25. Data Dependencies: 2 Nops 1 2 3 4 5 6 7 8 9 10 # demo-h2.ys F F D D F F E E D D F F M M E E D D F F W W M M E E D D F F 0x000: irmovq $10,%rdx W W M M E E D D F F 0x00a: irmovq $3,%rax W W M M E E D D 0x014: nop W W M M E E 0x015: nop W W M M 0x016: addq %rdx,%rax W W 0x018: halt Cycle 6 W W W R[%rax] 3 R[%rax] 3 R[%rax] 3 D D D valA R[%rdx] = 10 valB R[%rax] = 0 valB R[%rax] = 0 valB R[%rax] = 0 valA R[%rdx] = 10 valA R[%rdx] = 10 Error CS:APP3e 25

  26. Data Dependencies: 1 Nop # demo-h1.ys 1 2 3 4 5 6 7 8 9 F D F E D F F M E D D F F W 0x000: irmovq $10,%rdx M E E D D F F W M M E E D D 0x00a: irmovq $3,%rax W W M M E E 0x014: nop W W M M 0x015: addq %rdx,%rax W W 0x017: halt Cycle 5 W W R[%rdx] 10 R[%rdx] 10 M M_valE = 3 M_dstE = %rax D D Error valA R[%rdx] = 0 valB R[%rax] = 0 valB R[%rax] = 0 valA R[%rdx] = 0 CS:APP3e 26

  27. Data Dependencies: No Nop 1 2 3 4 5 6 7 8 # demo-h0.ys F D F E D F M E D F W 0x000: irmovq $10,%rdx M E D W M E 0x00a: irmovq $3,%rax W M 0x014: addq %rdx,%rax W 0x016: halt Cycle 4 M M_valE = 10 M_dstE = %rdx E e_valE 0 + 3 = 3 E_dstE = %rax D D Error valA R[%rdx] = 0 valA R[%rdx] = 0 valB R[%rax] = 0 valB R[%rax] = 0 CS:APP3e 27

  28. Branch Misprediction Example demo-j.ys 0x000: xorq %rax,%rax 0x002: jne t # Not taken 0x00b: irmovq $1, %rax # Fall through 0x015: nop 0x016: nop 0x017: nop 0x018: halt 0x019: t: irmovq $3, %rdx # Target (Should not execute) 0x023: irmovq $4, %rcx # Should not execute 0x02d: irmovq $5, %rdx # Should not execute Should only execute first 8 instructions CS:APP3e 28

  29. Branch Misprediction Trace # demo-j 1 2 3 4 5 6 7 8 9 F D F E D F M E D F W 0x000: xorq %rax,%rax M E D F F W M E D D 0x002: jne t # Not taken W M E E 0x019: t: irmovq $3, %rdx # Target W M M 0x023: irmovq $4, %rcx # Target+1 W W 0x00b: irmovq $1, %rax # Fall Through Cycle 5 M Incorrectly execute two instructions at branch target M_Cnd = 0 M_valA = 0x007 E E valE 3 dstE = %rdx dstE = %rdx valE 3 D D valC = 4 valC = 4 dstE = %ecx dstE = %rcx F F valC 1 valC 1 rB %rax rB %rax CS:APP3e 29

  30. Return Example demo-ret.ys 0x000: irmovq Stack,%rsp # Intialize stack pointer 0x00a: nop # Avoid hazard on %rsp 0x00b: nop 0x00c: nop 0x00d: call p # Procedure call 0x016: irmovq $5,%rsi # Return point 0x020: halt 0x020: .pos 0x20 0x020: p: nop # procedure 0x021: nop 0x022: nop 0x023: ret 0x024: irmovq $1,%rax # Should not be executed 0x02e: irmovq $2,%rcx # Should not be executed 0x038: irmovq $3,%rdx # Should not be executed 0x042: irmovq $4,%rbx # Should not be executed 0x100: .pos 0x100 0x100: Stack: # Initial stack pointer Require lots of nops to avoid data hazards CS:APP3e 30

  31. Incorrect Return Example Incorrectly execute 3 instructions following ret CS:APP3e 31

  32. Pipeline Summary Concept Break instruction execution into 5 stages Run instructions through in pipelined mode Limitations Can t handle dependencies between instructions when instructions follow too closely Data dependencies One instruction writes register, later one reads it Control dependency Instruction sets PC in way that pipeline did not predict correctly Mispredicted branch and return Fixing the Pipeline We ll do that next time CS:APP3e 32

  33. Part Two Overview Make the pipelined processor work! Data Hazards Instruction having register R as source follows shortly after instruction having register R as destination Common condition, don t want to slow down pipeline Control Hazards Mispredict conditional branch Our design predicts all branches as being taken Na ve pipeline executes two extra instructions Getting return address for ret instruction Na ve pipeline executes three extra instructions Making Sure It Really Works What if multiple special cases happen simultaneously? CS:APP3e 33

  34. Pipeline Stages Fetch Select current PC Read instruction Compute incremented PC Decode Read program registers Execute Operate ALU Memory Read or write data memory Write Back Update register file CS:APP3e 34

  35. PIPE- Hardware Pipeline registers hold intermediate values from instruction execution Forward (Upward) Paths Values passed from one stage to next Cannot jump past stages e.g., valC passes through decode CS:APP3e 35

  36. Data Dependencies: 2 Nops 1 2 3 4 5 6 7 8 9 10 # demo-h2.ys F F D D F F E E D D F F M M E E D D F F W W M M E E D D F F 0x000: irmovq $10,%rdx W W M M E E D D F F 0x00a: irmovq $3,%rax W W M M E E D D 0x014: nop W W M M E E 0x015: nop W W M M 0x016: addq %rdx,%rax W W 0x018: halt Cycle 6 W W W R[%rax] 3 R[%rax] 3 R[%rax] 3 D D D valA R[%rdx] = 10 valB R[%rax] = 0 valB R[%rax] = 0 valB R[%rax] = 0 valA R[%rdx] = 10 valA R[%rdx] = 10 Error CS:APP3e 36

  37. Data Dependencies: No Nop 1 2 3 4 5 6 7 8 # demo-h0.ys F D F E D F M E D F W 0x000: irmovq $10,%rdx M E D W M E 0x00a: irmovq $3,%rax W M 0x014: addq %rdx,%rax W 0x016: halt Cycle 4 M M_valE = 10 M_dstE = %rdx E e_valE 0 + 3 = 3 E_dstE = %rax D D Error valA R[%rdx] = 0 valA R[%rdx] = 0 valB R[%rax] = 0 valB R[%rax] = 0 CS:APP3e 37

  38. Stalling for Data Dependencies 1 2 3 4 5 6 7 8 9 10 11 # demo-h2.ys F D F E D F M E D F W M E D 0x000: irmovq $10,%rdx W M E 0x00a: irmovq $3,%rax W M 0x014: nop W 0x015: nop E D F M E D W M E bubble F D F W M 0x016: addq %rdx,%rax W 0x018: halt If instruction follows too closely after one that writes register, slow it down Hold instruction in decode Dynamically inject nop into execute stage CS:APP3e 38

  39. Stall Condition Source Registers srcA and srcB of current instruction in decode stage Destination Registers dstE and dstM fields Instructions in execute, memory, and write-back stages Special Case Don t stall for register ID 15 (0xF) Indicates absence of register operand Or failed cond. move CS:APP3e 39

  40. Detecting Stall Condition 1 2 3 4 5 6 7 8 9 10 11 # demo-h2.ys F D F E D F M E D F W M E D 0x000: irmovq $10,%rdx W M E 0x00a: irmovq $3,%rax W M 0x014: nop W 0x015: nop E D F M E D W M E bubble F D F W M 0x016: addq %rdx,%rax W 0x018: halt Cycle 6 W W_dstE = %rax W_valE = 3 D srcA = %rdx srcB = %rax CS:APP3e 40

  41. Stalling X3 1 2 3 4 5 6 7 8 9 10 11 # demo-h0.ys F D F E D M E W M E 0x000: irmovq $10,%rdx W M E 0x00a: irmovq $3,%rax W M E bubble W M bubble W bubble F D F D F D F D F E D M E W M 0x014: addq %rdx,%rax W 0x016: halt Cycle 6 W Cycle 5 W_dstE = %rax M Cycle 4 M_dstE = %rax E D e_dstE = %rax D srcA = %rdx srcB = %rax D srcA = %rdx srcB = %rax srcA = %rdx srcB = %rax CS:APP3e 41

  42. What Happens When Stalling? # demo-h0.ys Cycle 4 Cycle 5 Cycle 6 bubble bubble Cycle 7 Cycle 8 0x000: irmovq $10,%rdx Write Back Memory Execute Decode Fetch 0x000: irmovq $10,%rdx 0x00a: irmovq $3,%rax 0x00a: irmovq $3,%rax 0x000: irmovq $10,%rdx 0x00a: irmovq $3,%rax bubble bubble bubble 0x014: addq %rdx,%rax 0x00a: irmovq $3,%rax bubble bubble bubble 0x014: addq %rdx,%rax 0x016: halt 0x014: addq %rdx,%rax 0x014: addq %rdx,%rax 0x014: addq %rdx,%rax 0x014: addq %rdx,%rax 0x016: halt 0x016: halt 0x016: halt 0x016: halt 0x016: halt Stalling instruction held back in decode stage Following instruction stays in fetch stage Bubbles injected into execute stage Like dynamically generated nop s Move through later stages CS:APP3e 42

  43. Implementing Stalling Pipeline Control Combinational logic detects stall condition Sets mode signals for how pipeline registers should update CS:APP3e 43

  44. Pipeline Register Modes Rising clock clock Rising Input = y Output = x Output = y Normal x x y y stall = 0 bubble = 0 Rising clock clock Rising Input = y Output = x Output = x Stall x x x x bubble stall = 1 = 0 Rising clock clock Rising Output = nop Input = y Output = x n o p Bubble x x stall = 0 bubble = 1 CS:APP3e 44

  45. Data Forwarding Na ve Pipeline Register isn t written until completion of write-back stage Source operands read from register file in decode stage Needs to be in register file at start of stage Observation Value generated in execute or memory stage Trick Pass value directly from generating instruction to decode stage Needs to be available at end of decode stage CS:APP3e 45

  46. Data Forwarding Example 1 2 3 4 5 6 7 8 9 10 # demo-h2.ys F F D D F F E E D D F F M M E E D D F F W W M M E E D D F F 0x000: irmovq $10,%rdx W W M M E E D D F F 0x00a: irmovq $3,%rax W W M M E E D D 0x014: nop W W M M E E 0x015: nop W W M M 0x016: addq %rdx,%rax W W 0x018: halt Cycle 6 irmovq in write- back stage Destination value in W pipeline register Forward as valB for decode stage W R[%rax] 3 W_dstE = %rax W_valE = 3 D valA R[%rdx] = 10 valB W_valE = 3 srcA = %rdx srcB = %rax CS:APP3e 46

  47. Bypass Paths Decode Stage Forwarding logic selects valA and valB Normally from register file Forwarding: get valA or valB from later pipeline stage Forwarding Sources Execute: valE Memory: valE, valM Write back: valE, valM CS:APP3e 47

  48. Data Forwarding Example #2 # demo-h0.ys 1 2 3 4 5 6 7 8 F D F E D F M E D F W 0x000: irmovq $10,%rdx M E D W M E 0x00a: irmovq $3,%rax W M 0x014: addq %rdx,%rax W 0x016: halt Cycle 4 Register %rdx Generated by ALU during previous cycle Forward from memory as valA Register %rax Value just generated by ALU Forward from execute as valB M M_dstE = %rdx M_valE = 10 E E_dstE = %rax e_valE 0 + 3 = 3 D srcA = %rdx srcB = %rax valA M_valE = 10 valB e_valE = 3 CS:APP3e 48

  49. Forwarding Priority 1 2 3 4 5 6 7 8 9 10 # demo-priority.ys F F D D F F E E D D F F M M E E D D F F W W M M E E D D F F 0x000: irmovq $1, %rax W W M M E E D D 0x00a: irmovq $2, %rax W W M M E E 0x014: irmovq $3, %rax W W M M 0x01e: rrmovq %rax, %rdx W W 0x020: halt Multiple Forwarding Choices Which one should have priority Match serial semantics Use matching value from earliest pipeline stage Cycle 5 W W R[%rax] 3 R[%rax] 1 W M R[%rax] 3 R[%rax] 2 W E R[%rax] 3 R[%rax] 3 D D D valA R[%rdx] = 10 valB R[%rax] = 0 valB R[ valB 0 valA R[%rdx] = 10 valA R[%rax] = ? CS:APP3e 49

  50. Implementing Forwarding Add additional feedback paths from E, M, and W pipeline registers into decode stage Create logic blocks to select from multiple sources for valA and valB in decode stage CS:APP3e 50

More Related Content