Pipelining
Short pipelining lesson
Pipelining is basically the process of overlapping several instructions during execution. Let's go over a quick laundry pipelining example from
Patterson and Hennessy's COD:
Anyone who has done a lot of laundry has intuitively used pipelining. The nonpipelined approach to laundry would be:
1. Place one dirty load of clothes in the washer.
2. When the washer is finished, place the wet load in the dryer.
3. When the dryer is finished, place the dry load on a table and fold.
4. When folding is finished, ask your roommate to put the clothes away.
When your roommate is done, then start over with the next dirty load.
The pipelined approach takes much less time…. As soon as the washer is finished with the first load and placed in the dryer, you load the washer with the second dirty load. When the first load is dry, you place it on the table to start folding, move the wet load to the dryer, and the next dirty load into the washer.
Next you have your roommate put the first load away, you start folding the second load, the dryer has the third load, and you put the fourth load into the washer. At this point all steps -called stages in pipelining -are operating concurrently. As long as we have separate resources for each stage, we can pipeline the tasks.
Real world
Of course, CPUs have to run a variety of different tasks, not just a single, easily pipelined laundry operation. The instruction stream constantly changes; you can't count on running through a specific instruction path when you have to deal with conditional branches (if this, do this; else, do this instead) and data hazards where an instruction needs the results from a previous instruction that's still in the pipe. Keeping the instruction pipeline filled is a very complex task.