480 likes | 668 Views
Princess Sumaya University for Technology. Computer Architecture. Dr. Esam Al_Qaralleh. Data path. The processor : Data Path and Control. Two types of functional units: elements that operate on data values (combinational) elements that contain state (state elements).
E N D
Princess Sumaya University for Technology Computer Architecture Dr. Esam Al_Qaralleh
The processor : Data Path and Control • Two types of functional units: • elements that operate on data values (combinational) • elements that contain state (state elements)
Single Cycle Implementation • Typical execution: • read contents of some state elements, • send values through some combinational logic • write results to one or more state elements • Using a clock signal for synchronization • Edge triggered methodology
Control • Selecting the operations to perform (ALU, read/write, etc.) • Controlling the flow of data (multiplexor inputs) • Information comes from the 32 bits of the instruction • Example: lW $1, 100($2) • Value of control signals is dependent upon: • what instruction is being executed • which step is being performed
Single Cycle Implementation • Calculate cycle time assuming negligible delays except: • memory (2ns), ALU and adders (2ns), register file access (1ns)
Multicycle approach • Single Cycle Problems: • what if we had a more complicated instruction like floating point? • wasteful of area • One Solution: • use a “smaller” cycle time • have different instructions take different numbers of cycles • a “multicycle” datapath:
Multicycle Approach • Break up the instructions into steps, each step takes a cycle • balance the amount of work to be done • restrict each cycle to use only one major functional unit • At the end of a cycle • store values for use in later cycles (easiest thing to do) • introduce additional “internal” registers
Five Execution Steps • Instruction Fetch • Instruction Decode and Register Fetch • Execution, Memory Address Computation, or Branch Completion • Memory Access or R-type instruction completion • Write-back step • INSTRUCTIONS TAKE FROM 3 - 5 CYCLES!
A B C D Pipelining is Natural! • Pipelining provides a method for executing multiple instructions at the same time. • Laundry Example • Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold • Washer takes 30 minutes • Dryer takes 40 minutes • “Folder” takes 20 minutes
A B C D Sequential Laundry 6 PM Midnight 7 8 9 11 10 • Sequential laundry takes 6 hours for 4 loads • If they learned pipelining, how long would laundry take? Time 30 40 20 30 40 20 30 40 20 30 40 20 T a s k O r d e r
30 40 40 40 40 20 A B C D Pipelined Laundry: Start work ASAP 6 PM Midnight 7 8 9 11 10 • Pipelined laundry takes 3.5 hours for 4 loads Time T a s k O r d e r
30 40 40 40 40 20 A B C D Pipelining Lessons 6 PM 7 8 9 • Pipelining doesn’t help latency of single task, it helps throughput of entire workload • Pipeline rate limited by slowest pipeline stage • Multiple tasks operating simultaneously using different resources • Potential speedup = Number pipe stages • Unbalanced lengths of pipe stages reduces speedup • Time to “fill” pipeline and time to “drain” it reduces speedup • Stall for Dependences Time T a s k O r d e r
Basic DataPath What do we need to add to actually split the datapath into stages?
Ifetch Reg/Dec Exec Mem Wr The Five Stages of the Load Instruction Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 • Ifetch: Instruction Fetch • Fetch the instruction from the Instruction Memory • Reg/Dec: Registers Fetch and Instruction Decode • Exec: Calculate the memory address • Mem: Read the data from the Data Memory • Wr: Write the data back to the register file Load
IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB Pipelined Execution Time • On a processor multiple instructions are in various stages at the same time. • Assume each instruction takes five cycles Program Flow
Graphically Representing Pipelines Can help with answering questions like: • How many cycles does it take to execute this code? • What is the ALU doing during cycle 4? • Are two instructions trying to use the same resource at the same time?
Observations • Use separate instruction and data memories • To reduce memory conflict • The memory system must deliver 5 times the bandwidth, if the pipelined processor has a clock cycle that is equal to the unpipelined processor. • Register file is used in the two stages • One for reading in ID and one for writing in WB • 2 reads 1 write in every clock cycle • • Maintaining PC • IF stage: preparing the PC for the next instruction • ID stage: to compute the branch target address • Problem of a branch does not change the PC until the ID stage
Why Pipeline? • Suppose • 100 instructions are executed • The single cycle machine has a cycle time of 45 ns • The multicycle and pipeline machines have cycle times of 10 ns • The multicycle machine has a CPI of 4.6 • Single Cycle Machine • 45 ns/cycle x 1 CPI x 100 inst = 4500 ns • Multicycle Machine • 10 ns/cycle x 4.6 CPI x 100 inst = 4600 ns • Ideal pipelined machine • 10 ns/cycle x (1 CPI x 100 inst + 4 cycle drain) = 1040 ns • Ideal pipelined vs. single cycle speedup • 4500 ns / 1040 ns = 4.33 • What has not yet been considered?
Compare Performance Compare: Single-cycle, multicycle and pipelined control using SPECint2000 • Single-cycle: memory access = 200ps, ALU = 100ps, register file read and write = 50ps • 200+50+100+200+50=600ps • Multicycle: 25% loads, 10% stores, 11% branches, 2% jumps, 52% ALU • CPI = 4.12, The clock cycle = 200ps (longest functional unit) • Pipelined • 1 clock cycle when there is no load-use dependence • 2 when there is, average 1.5 per load • Stores and ALU take 1 clock cycle • Branches - 1 when predicted correctly and 2 when not, average 1.25 • Jump – 2 • 1.5x25%+1x10%+1x52%+1.25x11%+2x2% = 1.17 • Average instruction time: single-cycle = 600ps, multicycle = 4.12x200=824, pipelined 1.17x200 = 234ps • Memory access 200ps is the bottleneck. How to improve?
Can pipelining get us into trouble? • Yes:Pipeline Hazards • structural hazards: attempt to use the same resource two different ways at the same time • E.g., two instructions try to read the same memory at the same time • data hazards: attempt to use item before it is ready • instruction depends on result of prior instruction still in the pipeline add r1, r2, r3 sub r4, r2, r1 • control hazards: attempt to make a decision before condition is evaulated • branch instructions beq r1, loop add r1, r2, r3 • Can always resolve hazards by waiting • pipeline control must detect the hazard • take action (or delay action) to resolve hazards
Mem ALU Mem Mem Reg Reg ALU Mem Mem Reg Reg ALU ALU Mem Mem Reg Reg ALU Single Memory is a Structural Hazard Time (clock cycles) I n s t r. O r d e r Mem Reg Reg Load Instr 1 Instr 2 Mem Mem Reg Reg Instr 3 Instr 4 Detection is easy in this case! (right half highlight means read, left half write)
Structural Hazards limit performance • Example: if 1.3 memory accesses per instruction and only one memory access per cycle then • average CPI = 1.3 • otherwise resource is more than 100% utilized • Solution 1: Use separate instruction and data memories • Solution 2: Allow memory to read and write more than one word per cycle • Solution 3: Stall
Mem ALU Mem ALU ALU Mem Control Hazard Solutions • Stall: wait until decision is clear • Its possible to move up decision to 2nd stage by adding hardware to check registers as being read • Impact: 2 clock cycles per branch instruction => slow I n s t r. O r d e r Time (clock cycles) Mem Reg Reg Add Mem Reg Reg Beq Load Mem Reg Reg
Mem ALU Mem ALU ALU Control Hazard Solutions • Predict: guess one direction then back up if wrong • Predict not taken • Impact: 1 clock cycle per branch instruction if right, 2 if wrong (right 50% of time) • More dynamic scheme: history of 1 branch ( 90%) I n s t r. O r d e r Time (clock cycles) Mem Reg Reg Add Mem Reg Reg Beq Load Mem Mem Reg Reg
Mem ALU Mem ALU ALU ALU Control Hazard Solutions • Redefine branch behavior (takes place after next instruction) “delayed branch” • Impact: 1 clock cycles per branch instruction if can find instruction to put in “slot” ( 50% of time) • Launch more instructions per clock cycle=>less useful I n s t r. O r d e r Time (clock cycles) Mem Reg Reg Add Mem Reg Reg Beq Misc Mem Mem Reg Reg Load Mem Mem Reg Reg
Data Hazard---Forwarding • Use temporary results, don’t wait for them to be written • register file forwarding to handle read/write to same register • ALU forwarding
Can’t always forward • Load word can still cause a hazard: • an instruction tries to read a register following a load instruction that writes to the same register. • Thus, we need a hazard detection unit to “stall” the load instruction
Stalling • We can stall the pipeline by keeping an instruction in the same stage
Designing Instruction Set for Pipelining • MIPS instructions are the same length. • This makes much easer to fetch instructions in the first stage and to decode them in the second stage. • In IA-32 instructions vary from 1-17 bytes, pipelining is considerably more challenging. • All recent IA-32 architectures translate instructions into micro_operations, which are pipelined • MIPS has only few instruction formats, with the source registers fields in the same place • This symmetry – the second stage can read the register file at the same time that the hardware is decoding the type of instruction • Without this symmetry we would need to split stage 2
Designing Instruction Set for Pipelining • Memory operands only appears in loads or stores in MIPS • We can use the execute stage to calculate the memory and then access memory in the following stage • If we operate on operand in memory, stages 3 and 4 would expand to an address stage, memory stage and then execute stage • Operands must be aligned in memory • We can have instructions requiring two data memory access, the transfer can be done in a single pipeline stage
Summary: Pipelining • What makes it easy • all instructions are the same length • just a few instruction formats • memory operands appear only in loads and stores • What makes it hard? • structural hazards: suppose we had only one memory • control hazards: need to worry about branch instructions • data hazards: an instruction depends on a previous instruction • We’ll talk about modern processors and what really makes it hard: • exception handling • trying to improve performance with out-of-order execution, etc.
Summary • Pipelining is a fundamental concept • multiple steps using distinct resources • Utilize capabilities of the datapath by pipelined instruction processing • start next instruction while working on the current one • limited by length of longest stage (plus fill/flush) • detect and resolve hazards