[CS61C FA20] Lecture 22.2 - Pipelining II: Pipeline Hazards — Transcript
Full transcript
- 0:01[Music]
- 0:11hello
- 0:12welcome back to the module that deals
- 0:15with the pipeline processor design
- 0:17so far we took our single cycle cpu and
- 0:21modified it to make it a pipeline
- 0:24processor
- 0:25in that process we added some pipeline
- 0:27registers and moved some resources
- 0:29around
- 0:30so the things look a little bit easier
- 0:33to design
- 0:36but we didn't quite design a good
- 0:38pipeline processor
- 0:40it you know really badly suffers
- 0:43from some common issues that are
- 0:47associated with pipeline hazards
- 0:50now pipeline hazards
- 0:53stands for a collection of issues that
- 0:55pipeline processors
- 0:57encounter when we talk about
- 1:01pipelined processors the basic thing
- 1:04that differs
- 1:05between a pipeline processor and a
- 1:08single cycle processor
- 1:09is that we have multiple instructions in
- 1:11flight in a single cycle processor
- 1:16our instructions will really depend
- 1:19only on themselves every instruction
- 1:21completes and then the next instruction
- 1:25starts to execute and there is no really
- 1:28dependency between
- 1:30them in pipeline processors there are
- 1:33multiple instructions that are
- 1:35simultaneously being executed
- 1:37and if the results of one instruction
- 1:40affect the following instruction then
- 1:44we have an issue the following
- 1:46instruction
- 1:47cannot proceed there are generally three
- 1:51types of hazards
- 1:53so it is important to understand them
- 1:55because they have different
- 1:57solutions that will
- 2:01avoid running into those hazards
- 2:05in general why their whole called
- 2:07hazards because
- 2:09especially earlier on it was not clear
- 2:12who
- 2:13was going to take care of these issues
- 2:16they can be addressed by either a
- 2:18compiler
- 2:19or the pipeline pipeline processor
- 2:22designer
- 2:23but somebody has to take care of these
- 2:25hazards if nobody does the processor
- 2:27doesn't work
- 2:29or even worse works most of the time but
- 2:32pay
- 2:32fails from time to time and it's really
- 2:35difficult to find
- 2:36out when and why it fails
- 2:40so as i said there are three types of
- 2:42hazards that we can
- 2:43encounter and those are structural
- 2:45hazards data hazards and control hazards
- 2:49it is always a situation that prevents
- 2:52starting a new instruction while there
- 2:54is another instruction
- 2:55that is in flight structural hazards
- 3:01appear because of contention over a
- 3:04resource
- 3:05in most modern processors at least these
- 3:09that are not
- 3:10that complicated like the ones that we
- 3:12are designing in this class
- 3:14we are really going to run into
- 3:15structural hazards
- 3:18and the pipeline is designed to match
- 3:21the isa
- 3:22and isa prevents the existence of these
- 3:24hazards
- 3:25then the second type are data hazards
- 3:28data hazards
- 3:30essentially exists because of the
- 3:32dependency
- 3:33between the instructions so if there is
- 3:37one instruction that is in flight that
- 3:39is going to write
- 3:41the result into the register file the
- 3:43result
- 3:44that the following instruction cannot
- 3:48really depend
- 3:51cannot work with the same operand that
- 3:54is
- 3:54before it gets written back into the
- 3:56register file
- 3:59otherwise we will be working with an
- 4:01incorrect value
- 4:02we're going to talk a little bit more
- 4:04about that
- 4:05just in a bit and finally there is a
- 4:07control
- 4:08hazard the control hazards happen when
- 4:10we have branches
- 4:12if the following instruction that is
- 4:13being executed in the pipeline
- 4:15is following a branch
- 4:20so if there is a branch in the pipeline
- 4:21and there is another instruction after
- 4:23that that
- 4:23next instruction may be invalid if
- 4:26the branch ends up being taken
- 4:30so let's talk about structural hazards
- 4:33in a bit
- 4:34more of a detail the simplest
- 4:37type of structural hazard that we
- 4:39already addressed
- 4:40in our design even of a single cycle cpu
- 4:44is the contention between
- 4:48incrementing the program counter and
- 4:50performing arithmetic
- 4:52operations and when addressing
- 4:56the memory
- 4:59for example we could have made a mistake
- 5:03and left out the pc plus four adder and
- 5:06said
- 5:07let's use the lanes alu instead so every
- 5:10time we would have to
- 5:11add pc 4 to our instruction
- 5:14we would use the alu
- 5:18well we have an issue there right
- 5:22every time we
- 5:25need to add four to a prior encounter
- 5:28our alu would not be available
- 5:31so our processor would not work very
- 5:34well it would first
- 5:35you know in one cycle would add pc plus
- 5:38four
- 5:39and then in the next cycle would have to
- 5:41execute things so it was a very natural
- 5:43decision
- 5:44and we we just went through that to have
- 5:47a dedicated adder that
- 5:48increments the program counter um
- 5:52so in general structural hazards
- 5:56appear because two instructions
- 5:59in the pipeline compete for the same
- 6:02resource
- 6:03there are two ways to address structural
- 6:05hazards one
- 6:06is to stall and that's what i've just
- 6:09described as a possible outcome for not
- 6:12having a pc plus 4 either
- 6:14essentially the next instruction would
- 6:17stall
- 6:18until the previous instruction is not
- 6:21is is done is finished using that
- 6:24resource
- 6:26stall often means introducing
- 6:30knobs i'll see that in a bit then
- 6:34more a more more common solution is to
- 6:36add more hardware to our pipeline
- 6:39such that all instructions can execute
- 6:42concurrently
- 6:46so um let's take a look at the
- 6:50fairly straightforward structural hazard
- 6:52that can exist
- 6:53because of the register file so in
- 6:57risk five isa our instructions
- 7:01can access the register file three times
- 7:04there are two
- 7:05operands to be read and one to be
- 7:07written so
- 7:08our register file has to be able to
- 7:11support that
- 7:12otherwise we would have an a shortage of
- 7:15resources
- 7:16so our register file is designed to have
- 7:19two read ports
- 7:20and a right port there are remember
- 7:24three addresses that go into the input
- 7:26of the register file
- 7:28here's another subtlety in there
- 7:32in order to be able to complete all of
- 7:34this all of the
- 7:36operations in a single cycle or in a
- 7:38pipeline processor
- 7:39we made one assumption that the razer
- 7:42file is fairly fast
- 7:44so it is faster than many of the other
- 7:47units that we have in a processor
- 7:49we can read the register file in a 100
- 7:51picoseconds and we can also write to a
- 7:53register
- 7:53file in 100 picoseconds we'll see that
- 7:56that's a convenient thing that allows us
- 7:58to both read and write a register file
- 8:01in
- 8:01a single cycle
- 8:05but the key thing here is register file
- 8:07has to be designed
- 8:08to support three accesses per cycle
- 8:12simultaneously let's take a look at
- 8:16another type of a structural hazard that
- 8:18we may have
- 8:20it may be there may be a memory
- 8:21contention
- 8:23so in pretty much every instruction
- 8:26needs to
- 8:27access the instruction memory but some
- 8:31instructions
- 8:32need to work
- 8:35you know read or write the data to the
- 8:38memory
- 8:40and we said that we have this unified
- 8:42concept of a memory
- 8:43that we are working with the store
- 8:44program computer so there should be just
- 8:46one memory
- 8:47so every time there is a load or store
- 8:50it is going to contend with every other
- 8:53instruction for the memory access
- 8:55in this case it is shown
- 8:58that if you have a load word during
- 9:02the memory access phase another
- 9:04instruction that would perhaps
- 9:06be trying to read an instruction if you
- 9:08just said one memory
- 9:09this ad immediate would have to stall
- 9:12and would have to wait until the load
- 9:15word
- 9:15is done if we just had one memory
- 9:19so a solution to this is to have two
- 9:23memories
- 9:24but then you just contradict yourself or
- 9:27then don't we have
- 9:28just one memory and what's the story
- 9:32about two memories
- 9:33well we do have one main memory that
- 9:36lives in dram
- 9:37but we generally have cache that is on
- 9:40our processor die on our processor chip
- 9:44and we're going to see that in just next
- 9:46module in a couple of lectures
- 9:49essentially there are pieces of
- 9:53of their chunks of memory on our
- 9:56processor chip
- 9:57that have copies of the instructions
- 10:00that are have been copied from the main
- 10:02memory
- 10:03and copies of the data that has been
- 10:05copied from the main memory
- 10:06with two separate ways to access it so
- 10:09we don't have to contend
- 10:10for the main memory when we are fetching
- 10:14an instruction
- 10:15while another instruction is completing
- 10:18a read
- 10:19or a write
- 10:22all right so in summary
- 10:25structural hazards can exist but they
- 10:28are
- 10:28avoided by
- 10:32typically by the by the hardware design
- 10:36that matches the ic so we look through
- 10:39all the instructions that are
- 10:40in the isa and we make sure that our
- 10:43hardware is
- 10:44provisioned to support all all of these
- 10:47instructions
- 10:49during the depth of the pipeline that
- 10:51can exist concurrently
- 10:52during the depth of a pipeline
- 10:55so what we have seen is that our
- 11:00register file has to support whatever
- 11:03the isa requires us to have
- 11:07for it and that we need to have separate
- 11:11instruction and data memories or at
- 11:13least copies of instruction and data
- 11:15memory
- 11:16so we can access them separately
- 11:19that's it for structural hazards they're
- 11:21relatively straightforward to understand
- 11:24the next ones are data hazards which are
- 11:26a little bit trickier
- 11:29see you in a bit
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 22.2 - Pipelining II: Pipeline Hazards by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,477 words across 287 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.