the basics pipelining
play

The Basics: Pipelining J. Nelson Amaral University of - PowerPoint PPT Presentation

The Basics: Pipelining J. Nelson Amaral University of Alberta 1 The Pipeline Concept 2 Bauer p. 32 Pipeline Throughput and Latency IF ID EX MEM


  1. The ¡Basics: ¡Pipelining ¡ J. ¡Nelson ¡Amaral ¡ University ¡of ¡Alberta ¡ 1 ¡

  2. The ¡Pipeline ¡Concept ¡ 2 ¡ Bauer ¡p. ¡32 ¡

  3. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns Consider the pipeline above with the indicated delays. We want to know what is the pipeline throughput and the pipeline latency . Pipeline throughput: instructions completed per second. Pipeline latency: how long does it take to execute a single instruction in the pipeline. 3 ¡

  4. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns Pipeline throughput: how often is an instruction completed? 1 instr T = [ ] max lat ( IF ), lat ( ID ), lat ( EX ), lat ( MEM ), lat ( WB ) 1 instr = [ ] max 5 ns ,4 ns ,5 ns ,10 ns ,4 ns = 1 instr 10 ns Pipeline latency: how long does it take to execute an instruction in the pipeline? Is this right? 4 ¡

  5. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns Simply adding the latencies to compute the pipeline latency, only would work for an isolated instruction L(I1) = 28ns I1 IF ID EX MEM WB L(I2) = 33ns I2 IF ID EX MEM WB L(I3) = 38ns I3 IF ID EX MEM WB I4 IF ID EX MEM WB L(I5) = 43ns We are in trouble! The latency is not constant. This happens because this is an unbalanced pipeline. The solution is to make every stage the same length as the longest one. 5 ¡

  6. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns The slowest pipeline state also limits the latency!! I1 IF ID EX MEM WB L(I2) = 50ns I2 IF ID EX MEM WB I3 IF ID EX MEM WB I4 IF ID EX MEM 0 10 20 30 40 50 60 L(I1) = L(I2) = L(I3) = L(I4) = 50ns 6 ¡

  7. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns How long does it take to execute 20000 instructions in this pipeline? (disregard bubbles caused by branches, cache misses, and hazards) How long would it take using the same modules without pipelining? What is the speedup due to pipelining? 7 ¡

  8. Pipeline ¡Throughput ¡and ¡Latency ¡ IF ID EX MEM WB 5 ns 4 ns 5 ns 10 ns 4 ns The speedup that we got from the pipeline is: How can we improve this pipeline design? We need to reduce the unbalance to increase the clock speed. 8 ¡

  9. Pipeline ¡Throughput ¡and ¡Latency ¡ MEM1 IF ID EX WB MEM2 5 ns 4 ns 5 ns 5 ns 5 ns 4 ns Now we have one more pipeline stage. What is the throughput now? 1 instr T = [ ] max lat ( IF ), lat ( ID ), lat ( EX ), lat ( MEM 1), lat ( MEM 2), lat ( WB ) 1 instr = [ ] max 5 ns , 4 ns , 5 ns , 5 ns , 5 ns , 4 ns = 1 instr 5 ns What is the new latency for a single instruction? 9 ¡

  10. Pipeline ¡Throughput ¡and ¡Latency ¡ MEM1 IF ID EX WB MEM2 5 ns 4 ns 5 ns 5 ns 5 ns 4 ns I1 IF ID EX WB MEM1 MEM1 I2 IF ID EX WB MEM1 MEM1 I3 IF ID EX WB MEM1 MEM1 I4 IF ID EX WB MEM1 MEM1 I5 IF ID EX WB MEM1 MEM1 I6 IF ID EX WB MEM1 MEM1 I7 IF ID EX WB MEM1 MEM1 10 ¡

  11. Pipeline ¡Throughput ¡and ¡Latency ¡ MEM1 IF ID EX WB MEM2 5 ns 4 ns 5 ns 5 ns 5 ns 4 ns How long does it take to execute 20000 instructions in this pipeline? (disregard bubles caused by branches, cache misses, etc, for now) What is the speedup that we get from pipelining? 11 ¡

  12. Pipeline ¡Throughput ¡and ¡Latency ¡ MEM1 IF ID EX WB MEM2 5 ns 4 ns 5 ns 5 ns 5 ns 4 ns What have we learned from this example? 1. It is important to balance the delays in the stages of the pipeline 2. The throughput of a pipeline is 1/max(delay). 3. The latency is N × max(delay), where N is the number of stages in the pipeline. 12 ¡

  13. ExecuMon ¡Snapshot ¡ 13 ¡ Bauer ¡p. ¡33 ¡

  14. Pipeline ¡with ¡Control ¡Unit ¡ 14 ¡ Bauer ¡p. ¡34 ¡

  15. Data ¡Hazards ¡and ¡Forwarding ¡ Example ¡1: ¡ i: ¡ ¡ ¡R7 ¡← ¡R12 ¡+ ¡R15 ¡ Read-­‑AYer-­‑Write ¡(RAW) ¡ dependencies ¡ (true ¡dependencies) ¡ i+1: ¡ ¡R8 ¡← ¡R7 ¡– ¡R12 ¡ Write-­‑AYer-­‑Read ¡(WAR) ¡ i+2: ¡ ¡R15 ¡← ¡R8 ¡+ ¡R7 ¡ dependencies ¡ (anM ¡dependencies) ¡ 15 ¡ Bauer ¡p. ¡35 ¡

  16. Data ¡Hazards ¡and ¡Forwarding ¡ v ¡ v ¡ v ¡ 16 ¡ Bauer ¡p. ¡36 ¡

  17. Forwarding ¡ 17 ¡ Bauer ¡p. ¡37 ¡

  18. Load-­‑ALU ¡RAW ¡Dependency ¡ Example ¡2: ¡ i: ¡ ¡ ¡R6 ¡← ¡Mem[R2] ¡ i+1: ¡ ¡R7 ¡← ¡R6 ¡+ ¡R4 ¡ The ¡data ¡from ¡the ¡load ¡is ¡not ¡available ¡unMl ¡the ¡Mem/WB ¡of ¡instrucMon ¡i , ¡ but ¡it ¡is ¡needed ¡at ¡the ¡ID/EX ¡of ¡instrucMon ¡i+1 ¡ Cannot ¡forward ¡ back ¡on ¡Mme! ¡ 18 ¡ Bauer ¡p. ¡36 ¡

  19. Bubble ¡because ¡of ¡load ¡ 19 ¡ Bauer ¡p. ¡38 ¡

  20. Priority ¡on ¡Forwarding ¡ The ¡RAW ¡from ¡ i+1 ¡ to ¡i+2 ¡ must ¡take ¡priority ¡over ¡ ¡ the ¡RAW ¡from ¡i ¡ to ¡i+2 . ¡ Example: ¡ i: ¡ ¡ ¡R10 ¡← ¡R4 ¡+ ¡R5 ¡ i+1: ¡ ¡R10 ¡← ¡R4 ¡– ¡R10 ¡ i+2: ¡ ¡R8 ¡← ¡R10 ¡+ ¡R7 ¡ 20 ¡ Bauer ¡p. ¡38 ¡

  21. Forwarding ¡from ¡Mem/WB ¡to ¡Mem ¡ Example: ¡ i: ¡ ¡ ¡R5 ¡← ¡Mem[R6] ¡ i+1: ¡ ¡Mem[R8] ¡← ¡R5 ¡ AYer ¡the ¡load, ¡the ¡contents ¡of ¡the ¡Mem/WB ¡register ¡ must ¡be ¡forwarded ¡to ¡be ¡wrifen ¡to ¡memory ¡(not ¡only ¡ to ¡R5). ¡ ¡ 21 ¡ Bauer ¡p. ¡39 ¡

  22. Pipelining ¡with ¡Forwarding ¡and ¡Stall ¡ 22 ¡ Bauer ¡p. ¡38 ¡

  23. Control ¡Hazards ¡(branches) ¡ 23 ¡ Bauer ¡p. ¡40 ¡

  24. Control ¡Hazards: ¡ExcepMons ¡and ¡ InterrupMons ¡ • ExcepMons ¡can ¡occur ¡in ¡any ¡stage ¡(except ¡WB) ¡ – IF: ¡page ¡faults ¡ – ID: ¡Illegal ¡opcodes ¡ – EX: ¡arithmeMc ¡excepMons ¡ – Mem: ¡illegal ¡address, ¡page ¡faults ¡ • InterrupMons: ¡ – I/O ¡terminaMon, ¡Mme-­‑outs ¡ – Power ¡failures ¡ 24 ¡ Bauer ¡p. ¡40 ¡

  25. Handling ¡ExcepMons/InterrupMons ¡ Save ¡the ¡Process ¡State ¡ Clear ¡ExcepMon ¡CondiMon ¡ ? ¡ “Correct” ¡ Perform ¡ Abort ¡Program ¡ ExcepMon ¡ Unrelated ¡Task ¡ Schedule ¡Process ¡Restart ¡ 25 ¡ Bauer ¡p. ¡41 ¡

  26. Precise ¡ExcepMons ¡in ¡a ¡Pipeline ¡ • If ¡an ¡excepMons ¡happens ¡in ¡instrucMon ¡ i : ¡ • InstrucMons ¡ i-­‑1, ¡i-­‑2, ¡… ¡ complete ¡normally ¡and ¡ contribute ¡to ¡the ¡saved ¡state ¡of ¡the ¡process ¡ • InstrucMons ¡ i, ¡i+1, ¡i+2, ¡ … ¡become ¡no-­‑ops ¡ • AYer ¡the ¡excepMon ¡is ¡handled, ¡execuMon ¡re-­‑starts ¡at ¡ instrucMon ¡i ¡ – T he ¡PC ¡saved ¡is ¡the ¡PC ¡of ¡instrucMon ¡ i. ¡ ⋅⋅⋅ ¡ i-­‑2 ¡ Complete ¡normally ¡ i-­‑1 ¡ ExcepMon ¡happens ¡here ¡→ ¡ i ¡ no-­‑op ¡ ←ExecuMon ¡re-­‑starts ¡here ¡ i+1 ¡ no-­‑op ¡ i+2 ¡ no-­‑op ¡ ⋅⋅⋅ ¡ no-­‑op ¡ 26 ¡ Bauer ¡p. ¡41 ¡

  27. ImplemenMng ¡Precise ¡ExcepMons ¡in ¡ the ¡Pipeline ¡ 1. Flag ¡the ¡pipeline ¡register ¡at ¡the ¡right ¡of ¡the ¡ stage ¡where ¡excepMon ¡was ¡detected ¡ – This ¡Flag ¡moves ¡along ¡the ¡pipeline ¡ 2. Set ¡all ¡control ¡lines ¡at ¡a ¡stage ¡with ¡the ¡flag ¡to ¡ transform ¡the ¡instrucMon ¡into ¡a ¡no-­‑op ¡ 3. Stop ¡instrucMon ¡fetching ¡ 4. When ¡the ¡flag ¡reaches ¡the ¡Mem/WB ¡stage, ¡ save ¡the ¡PC ¡of ¡that ¡instrucMon ¡as ¡the ¡ excep0on ¡PC ¡ ¡ 27 ¡ Bauer ¡p. ¡41 ¡

  28. Program ¡Order ¡X ¡Temporal ¡Order ¡ divide-­‑by-­‑zero ¡excepMon ¡ page-­‑fault ¡excepMon ¡ Which ¡excepMon ¡occurs ¡first ¡in ¡Mme? ¡ Which ¡excepMon ¡should ¡be ¡handled ¡first? ¡ 28 ¡ Bauer ¡p. ¡41 ¡

  29. Can’t ¡avoid ¡Load/ALU ¡instr. ¡bubble ¡ Design ¡Issues: ¡ Branch ¡resoluMon ¡in ¡EX ¡stage ¡→ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Two-­‑cycle ¡branch ¡penalty ¡ Mem ¡stage ¡unused ¡for ¡ALU ¡instr ¡ 29 ¡ Bauer ¡p. ¡38 ¡

  30. AlternaMve ¡Pipelining ¡Design: ¡ Avoiding ¡the ¡load ¡latency ¡penalty ¡ Example: ¡ ¡ ¡i: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R4 ¡← ¡Mem[R8] ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡i+1: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R7 ¡← ¡R4 ¡+ ¡R5 ¡ 30 ¡ Bauer ¡p. ¡43 ¡

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