




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















t^
Pi
li i
Lecture 9 – Pipelining I
We have been working with a simple model of how
g^
p
instructions are executed:
do {do {
fetch instruction at Mem[PC];PC = PC + 4; // advance to next instructionexecute fetched instruction; } while (processor not halted);
-^
In reality, instruction execution is broken into severalsteps, each of which is performed by separatehardware components
3
Instruction Fetch– Get the next instruction from memory– Increment Program Counter by 4
Instruction Decode– Figure out what the instruction says to do
f
registers we may need before the instruction isregisters we may need before the instruction isfully decoded
5
Execute– On a memory reference, add up base and offset– On an arithmetic instruction, do the math
Memory Access– If load or store, access memory
Write back
Place the results in the appropriate register
6
IF get instruction at PC from memory; increment PC
g^
y;
op code
base reg
src/dest
offset or immediate value
010111
10000
01000
0000000000010000
ID determine what 010111 is– 010111 is lw
f $
that we don’t care about $t2). Let’s assume$s0=0x200D1C00 and $t2=77763$^
EX add 16
10
to 0x200D1C00 = 0x200D1C
MEM load the word stored at 0x200D1C
-^
WB store loaded value in $t
8
-^
Executing a MIPS instruction can take up to five steps.
Step
Name
Description
Instruction Fetch
IF^
Read an instruction from memory.
Instruction Decode
ID^
Read source registers and generate control signals.
Execute
EX
Compute an R-type result or a branch outcome.
Memory
MEM
Read or write the data memory.
Writeback
WB
Store a result in the destination register.
-^
However, as we saw, not all instructions need all five steps.
Instruction
Steps required
beq
IF^
ID^
EX
R-type
IF^
ID^
EX
WB
sw
IF^
ID^
EX
MEM
lw^
IF^
ID^
EX
MEM
WB
9
IF
ID
EX
MEM
WB
IF
ID
EX
MEM
WB
inst 1inst 2
Latency
What’s the latency for this implementation?
One instruction takes 5 clock cyclesCycles per Instruction (CPI) = 5
Throughput
Throughput
number of instructions executed per unit time
What’s the throughput of this implementation?
One instruction is completed every 5 clock cyclesA^
CPI
5
Average CPI = 5
11
-^
Assuming you’ve got:– One washer (takes 30 minutes)– One drier (takes 40 minutes)– One “folder” (takes 20 minutes)
-^
It takes 90 minutes to wash, dry, and fold 1 load oflaundry.– How long does 4 loads take?
12
-^
Start each load as soon as possible– Overlap loads– Overlap loads^ 6 PM
7
8
9
10
11
Midnight
Time
30
40
40
40
40
20
-^
Pipelined laundry takes 3.5 hours
14
Pipelining doesn’t help latencyof single load it helps
6 PM
7
8
9
of
single load, it helps throughput of entire workload ^
Pipeline rate limited by slowesti
li^
t
Time
30
40
40
40
40
20
pi
peline stage ^
Multiple tasks operatingsimultaneously using differentresources ^
Potential speedup = Numberpipe stagesp p
g
Unbalanced lengths of pipestages reduces speedup ^
Time to “fill” pipeline and time ^
Time to “fill” pipeline and timeto “drain” it reduces speedup
15
inst 1inst 2
inst 3inst 4
inst 5
What’s the latency of this implementation?
-^
What’s the throughput of thisimplementation?
17
A pipeline with N stages could improve throughput by
p p
g^
p^
g p
y
N times, but– each stage must take the same amount of time– each stage must always have work to do– there may be some overhead to implementAlso latency for each instruction may go up
-^
Also, latency for each instruction may go up– Within some limits, we don’t care
18
We’ll make our pipeline 5 stages long
p p
g^
g
We want to support executing 5 instructionssimultaneously: one in each stage.
20
Clock cycle
1
2
3
4
5
6
7
8
9
lw^
$t
4($sp)
IF^
ID^
EX^
MEM
WB
lw^
$t0, 4($sp)
IF^
ID^
EX^
MEM
WB
lw^
$t1, 8($sp)
IF^
ID^
EX
MEM
WB
lw^
$t2, 12($sp)
IF^
ID^
EX^
MEM
WB
6 PM
7
8
9
lw^
$t3, 16($sp)
IF^
ID^
EX^
MEM
WB
lw^
$t4, 20($sp)
IF^
ID^
EX^
MEM
WB
6 PM
7
8
9
Time
30
40
40
40
40
20
21