pipelining what is it? how does it work? what are the benefits? what could go wrong? by derek...

79
Pipelining • What is it? • How does it work? • What are the benefits? • What could go wrong? By Derek Closson

Post on 15-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

Pipelining

• What is it?

• How does it work?

• What are the benefits?

• What could go wrong?

By Derek Closson

Page 2: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What is pipelining?

Pipelining is a design feature that allows individual common processor tasks to run simultaneously, such as:

FetchDecodeExecute

Page 3: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What is pipelining?

Or, more specifically in modern computers,

Instruction readDecodeOperand readExecuteOperand write

Page 4: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What is pipelining?

• No more “one instruction at a time” processing

• Processor works simultaneously on multiple instructions

• Each instruction is at a different stage (or is being delayed until its next stage is open)

Page 5: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

• First instruction is fetched from memory

Page 6: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

• First instruction is fetched from memory

• First instruction is decoded;second instruction is fetched

Page 7: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

• First instruction is fetched from memory

• First instruction is decoded;second instruction is fetched

• First instruction’s operands are fetched;second instruction is decoded;third instruction is fetched

Page 8: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

• First instruction is fetched from memory

• First instruction is decoded;second instruction is fetched

• First instruction’s operands are fetched;second instruction is decoded;third instruction is fetched

• And on, and on, and on…

Page 9: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

• Because each instruction demands one stage of the processor, the maximum number of simultaneous instructions is the number of stages in the processor

Page 10: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

A short animation

of simple processor routines

Page 11: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 12: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 13: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 14: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 15: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 16: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 17: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 18: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 19: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 20: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 21: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 22: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 23: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 24: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 25: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 26: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 27: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 28: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 29: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 30: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 31: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 32: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 33: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 34: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 35: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 36: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 37: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 38: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 39: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 40: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 41: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 42: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 43: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 44: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 45: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 46: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 47: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 48: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

How does pipelining work?

A short(er) animation

of pipelined processor routines

Page 49: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 50: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 51: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 52: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 53: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 54: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 55: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 56: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 57: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 58: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 59: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 60: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 61: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 62: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 63: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 64: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 65: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 66: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 67: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 68: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 69: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 70: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson
Page 71: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What are the benefitsof pipelining?

• Uses most (if not all) of a processor’s ability at all timesEfficiency goes up

• Relatively minor hardware changes give more completed cycles per secondSpeed goes up

Page 72: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong in pipelines?

• Data hazards

• Control hazards

• Structural hazards

Page 73: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Data hazards

• Two instructions at different stagesOne instruction needs the results ofthe other instruction’s operation

…add %r1, 5, %r2add %r2, 7, %r3…

Page 74: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Data hazards

• Well-designed programs can anticipate this, and spread the connected commands out with other operations (or nop in a pinch)

…add %r1, 5, %r2 (i1 fetch)sub %r4, 7, %r8 (i1 decode)mov %r5, %r6 (i1 read)add %r2, 7, %r3 (i1 execute, i2 fetch)nop (i1 write, i2 decode)…

Page 75: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Data hazards

• Hardware can detect some data hazards and “forward” the information to the instructions that need it, even as the data goes to the registers

• Otherwise, programs may simply have bad data - testing and good programming are the best cures!

Page 76: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Control hazards

• Instructions are read sequentially from memory - even though loops may return to previous statements

• Instructions following the loop are already in the pipeline!

• Or, simple if/else blocks of code. Which block do you get instructions from?

Page 77: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Control hazards

• At worst, the entire pipeline must be flushed: hardware can stall the influx of new instructions until the conditional is evaluated

Page 78: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Control hazards

• Branch prediction inserts a couple instructions of its own to guess the outcome of the conditional

• If prediction is usually correct,fewer cycles lost on average

• If prediction is wrong,flush the pipeline and undo any improper commands

Page 79: Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson

What can go wrong…?Structure hazards

• Two different instructions try to use the same hardware resource

• One instruction will obviously get access first, second instruction must be stalled (maybe along with all other instructions behind it)

• Again, careful programming will prevent this