Docsity

Pipelining in MIPS Processors: Overlapping Instruction Execution, Slides of Computer Science

Partial preview of the text

Download Pipelining in MIPS Processors: Overlapping Instruction Execution and more Slides Computer Science in PDF only on Docsity!

CSE 410Computer Systems

L^

t^

Pi

li i

I

Lecture 9 – Pipelining I

Our Simplified Execution ModelOur

Simplified Execution Model

•^

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

IF and ID StagesIF

and ID Stages

Instruction Fetch– Get the next instruction from memory– Increment Program Counter by 4

Instruction Decode– Figure out what the instruction says to do

G

f

  • Get values from the named registers– Simple instruction format means we know which

registers we may need before the instruction isregisters we may need before the instruction isfully decoded

5

EX MEM and WB stagesEX

, MEM, and WB stages

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

O

  • Otherwise do nothing

Write back

Place the results in the appropriate register

  • Place the results in the appropriate register

6

Example: lw $t2 16($s0)Example:

lw $t2, 16($s0)

•^

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 $

$^

(^

  • get contents of $s0 and $t2 (we don’t yet know

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

Instruction execution reviewInstruction

execution review

-^

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

Latency & Throughput

y

g p

IF

ID

EX

MEM

WB

IF

ID

EX

MEM

WB

inst 1inst 2

Latency

  • time it takes for an individual instruction to execute

What’s the latency for this implementation?

One instruction takes 5 clock cyclesCycles per Instruction (CPI) = 5

Throughput

  • number of instructions executed per unit time

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

A relevant questionA

relevant question

-^

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

Laundry PipeliningLaundry

Pipelining

-^

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 LessonsPipelining

Lessons

ƒ^

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

Pipelined Latency & Throughput

p

y

g p

IF

ID

EX

MEM

WB

IF

ID

EX

MEM

WB

inst 1inst 2

IF

ID

EX

MEM

WB

IF

ID

EX

MEM

WB

inst 3inst 4

IF

ID

EX

MEM

WB

inst 5

•^

What’s the latency of this implementation?

-^

What’s the throughput of thisimplementation?

17

Pipelined AnalysisPipelined

Analysis

•^

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

Making Pipelining WorkMaking

Pipelining Work

•^

We’ll make our pipeline 5 stages long

p p

g^

g

  • Stages are: IF, ID, EX, MEM, and WB -^

We want to support executing 5 instructionssimultaneously: one in each stage.

20

Pipelining LoadsPipelining

Loads

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