Docsity

Pipelining: Improving CPU Performance through Instruction Processing Simultaneously - Prof, Study notes of Computer Architecture and Organization

Toggle sidebar
bg1
ECEN 4243 Computer Architecture
Pipelining February 20, 2008 page 1 of 10
Pipelining
The problem with the unpipelined design is that each instruction must finish before
another instruction can start. The hardware that we have designed is not used very effi-
ciently with this scheme. For example, the ALU is only used when none of the other hard-
ware modules are used; it does nothing in the other modules are in use. The basic idea of
pipelining is to take advantage of the unused time of the CPU components so that more
than one instruction is being processed simultaneously, i.e let other instructions start with-
out waiting for the previous instruction to finish.
Fig. 6.3, p. 373 compares unpipelined timing with pipelined timing. Note that the pipeline
processes instructions much faster using the same hardware units with the same delays for
each module.
Each instruction looks like we are using multiple copies of the unpipelined design as in
fig. 6.10, p. 387, but this would still be very inefficient because each individual copy is
inefficient. Instead a pipelined design divides the original hardware into pieces, called
stages.
In the examples that follow, we are going to divide the original single cycle MIPS design
into 5 stages as shown in fig. 6.9, p. 385.
During every clock period, each stage processes inputs provided by the previous stage and
provides outputs to be used by the next stage. In this way, each piece of the original hard-
ware is kept busy doing something useful during each clock period, instead of 1/5 of the
clock periods. The intermediate results between stages are stored in pipeline registers
IF/ID, ID/EX, EX/MEM and MEM/WB in fig. 6.11, p. 388.
Pipeline Performance
Throughput. Slightly different performance measures are used when evaluating the effec-
tiveness of pipelining. At this point, we can view the instruction set as fixed and we want
to consider various hardware alternatives to implement the instructions. If we use
CPUtime = (IC)(CPI)(T)
as our performance measure, the IC is determined by the choice of instruction set and will
be the same for all pipeline alternatives. It is more common to use
as the pipeline performance measure. This is related to the previous performance mea-
sures as
throughput instructions
time
-------------------------------
=
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Pipelining: Improving CPU Performance through Instruction Processing Simultaneously - Prof and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Pipelining

The problem with the unpipelined design is that each instruction must finish before another instruction can start. The hardware that we have designed is not used very effi- ciently with this scheme. For example, the ALU is only used when none of the other hard- ware modules are used; it does nothing in the other modules are in use. The basic idea of pipelining is to take advantage of the unused time of the CPU components so that more than one instruction is being processed simultaneously, i.e let other instructions start with- out waiting for the previous instruction to finish.

Fig. 6.3, p. 373 compares unpipelined timing with pipelined timing. Note that the pipeline processes instructions much faster using the same hardware units with the same delays for each module.

Each instruction looks like we are using multiple copies of the unpipelined design as in fig. 6.10, p. 387, but this would still be very inefficient because each individual copy is inefficient. Instead a pipelined design divides the original hardware into pieces, called stages.

In the examples that follow, we are going to divide the original single cycle MIPS design into 5 stages as shown in fig. 6.9, p. 385.

During every clock period, each stage processes inputs provided by the previous stage and provides outputs to be used by the next stage. In this way, each piece of the original hard- ware is kept busy doing something useful during each clock period, instead of 1/5 of the clock periods. The intermediate results between stages are stored in pipeline registers IF/ID, ID/EX, EX/MEM and MEM/WB in fig. 6.11, p. 388.

Pipeline Performance

Throughput. Slightly different performance measures are used when evaluating the effec- tiveness of pipelining. At this point, we can view the instruction set as fixed and we want to consider various hardware alternatives to implement the instructions. If we use

CPUtime = (IC)(CPI)(T)

as our performance measure, the IC is determined by the choice of instruction set and will be the same for all pipeline alternatives. It is more common to use

as the pipeline performance measure. This is related to the previous performance mea- sures as

throughput instructions time

Note that using throughput as an overall system performance measure is dangerous in that there is no penalty for using an overly large number of instructions in useful programs. It should be adequate for evaluating design alternatives once the instruction set is fixed.

Latency. Unfortunately, latency is defined in different ways by different people. It refers to the amount of time one has to wait to get information out of a pipeline after information is put in. We use the following definition.

Latency: The total time to get information out of the pipeline.

Latency = (no. of clocks for single instruction)(T)

MIPS Performance. Let’s compare the unpipelined single cycle MIPS as in fig. 6.9, p. 385 with the pipelined MIPS as in fig. 6.11, p. 388.

Unpipelined MIPS as in fig. 6.9, p. 385 (for simplicity assume each stage has the same delay, Tstage):

Ideal Pipelined MIPS as in fig. 6.11, p. 388:

(one instructions is started and finished every Tstage seconds)

(each instruction must go through 5 stages to finish)

The pipelined version has five times the throuput even though the latency is the same. Note that this is the performance of the ideal MIPS pipeline. The real pipelined MIPS does not do quite this well as we will see later.

Note that the memory data transfer must be able to occur at the same time as the instruc- tion fetch for another instruction. In fact, the instruction fetch is occuring during every clock cycle, and it would hog the memory bus making it impossible to do a memory data

throughput

IC

CPUtime

( CPI) ( T)

= =^ -----------------------

CPI = 1

T = 5T (^) stage

throughput

5T (^) stage

latency = 5T (^) stage

CPI = 1

T = T (^) stage

throughput

T (^) stage

latency = 5T (^) stage

When we are forced to decrease the clock period to the point where register delays are sig- nificant, pipelining gives a speedup less than n , the number of stages.

When the register delays, td + tsu , become a large fraction of the clock period, there is no more speedup from additional pipelining.

adder

cell

g0 p0 c

d

adder

cell

g31 p31 c

d

adder

cell

g1 p1 c

d

Carry Chain

Cout Cin

a(0) b(0) a(1) b(1) a(31)b(31)

S

S

register register

speedup

T unpiped T piped

T unpiped t (^) d + T unpiped ⁄ n + t (^) su

=^ -----------------------------------------------

n

1 n

t (^) d + t (^) su T unpiped

=^ -------------------------------------

speedup

n

T unpiped t (^) d + t (^) su

T unpiped t (^) d + t (^) su

Pipelining the Registers and the ALU

Pipelining techniques can be used to make the utilization of the register file and the ALU more efficient. Recall that in the unpipelined design, the register file and the ALU must each wait for the other before beginning work on a new instruction. We used latches to allow reading and writing to the register file over the same two busses. If the latches are replaced with registers, the following pipelined system results

With the A and B registers clocked by CL, the ALU has a whole clock cycle until its out- put is saved in the D register without having to wait for register file reads or writes.

The ALU output data is written into the register file from the D register during the next half clock cycle. This requires using the non-inverted delayed clock to control the tri-state buffer. The wr control signal on the register file requires special timing as explained in the design projects. We can think of WR as being approximately the same as CL here.

The ALU input data for the next instruction is read from the register file during the next half clock cycle. The input data is saved in the A and B registers at the beginning of the next clock cycle with the delayed inverted clock to control the register file read so that there is no hold time violation for register A and B. In this way, the register file does not have to wait for the ALU either.

Reg

File

CL

A-select

B-select

A

B

ALU

CL_D

A data bus

B data bus

rd

wr

CL_D

WR

D

CL

The clock can be twice as fast as the unpipelined design. Since one instruction is com- pleted each clock period, the throughput of the pipelined system is now twice what it was in the unpipelined system. The pipeline latency is about the same as the total delay in the unpipelined system.

Note that the operands for an instruction are read before the previous instruction writes its results in the register file. This can cause problems which we will handle later.

Pipelining LOAD and STORE

The rather elegant pipeline for the register and ALU is not easily expanded to include the extra operations needed for the LOAD and STORE instructions. The problem is that the data transfer from/to external memory must take place during the register write time; oth- erwise the register-ALU pipeline timing will have to be changed. Unfortunately, the address computation takes up most of the time before the data transfer with external mem- ory must occur, leaving only a half clock cycle (the usual register write time) for the exter- nal memory to respond to the address and complete the data transfer. The solutions are:

  1. Design very fast external memory that can respond in a half clock cycle (too expen- sive).
  2. Stall the pipeline until the external memory responds. This would mean that the CPU does nothing useful until the memory responds.
  3. Add more stages to the pipeline so that there is enough time for the memory to respond. This is the approach taken by the authors when they added the MEM stage. See fig. 6.11, p. 388

t

t

Reg

Read

Reg

Write

ALU Exe-

cute

t

Instr

#i-

Instr

#i

Instr

#i+

Reg

Read

Reg

Write

ALU Exe-

cute

Reg

Read

ALU Exe-

cute

The A and B registers are part of the ID/EX pipeline register and the D register is part of the EX/MEM pipeline register. Note that adding the MEM stage (not used by register - register instructions) does NOT reduce the throughput. Without the MEM stage:

With the MEM stage:

The increased latency makes it more difficult to make the pipeline work correctly as we shall see, but it does not decrease performance.

  1. Provide a separate LOAD/STORE unit that will handle the register-memory data trans- fer while the main instruction pipeline goes forward. This idea is studied in the advanced computer architecture course.

MIPS Pipeline Operation. The hardware used for each stage in the MIPS pipeline is shown for a load instruction in figs. 6.12 - 6.14, pp. 389 - 391.

The operation of ALU type instructions is similar except the ALU data is passed through the MEM stage without being used for the data memory (the bypass path in the MEM stage).

The operation of store instructions is slightly different in the EX, MEM and WB stages as shown in figs. 6.15 - 6.16, pp. 393 - 394.

These diagrams are ordinarily to cumbersome to draw. Instead one usually draws simpli- fied pipeline diagrams as in figs. 6.19 - 6.20, p. 397.

Going across horizontally in the diagram shows when each instruction uses each stage of the pipeline. Going down vertically shows which instructions are in which stage at any particular time.

A vertical slice through the pipeline diagram at each clock cycle gives the “snapshot” shown in fig. 6.21, p. 398, showing where each instruction is in the pipeline.

throughput

T

=^ ---

latency = 4

throughput

T

=^ ---

latency = 5

ID/EX

MEM/WB

I-bus

CL

CL

Reg File

Aselect

Bselect

ALU

MUX

CL IF/ID

op decoder

rs decoder

rs decoder

rd decoder

CL EX/MEM