Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
PROFESSOR
Hello, welcome back to the module that deals with the pipeline processor design. So far, we took our single-cycle CPU and modified it to make it a pipeline processor.
In that process, we added some pipeline registers and moved some resources around so that things look a little bit easier to design.
We didn't quite design a good pipeline processor. It really badly suffers from some common issues that are associated with pipeline hazards.
Pipeline hazards stands for a collection of issues that pipeline processors encounter.
When we talk about pipeline processors, the basic thing that differs between a pipeline processor and a single-cycle processor is that we have multiple inspections in flight.
In a single-cycle processor, our instructions really depend only on themselves.
Every instruction completes and then the next instruction starts to execute and there is no, really, dependency between them.
In pipeline processors, there are multiple instructions that are simultaneously being executed.
And if the results if one instruction affect the following instruction, then we have an issue, the following instruction cannot proceed.
There are generally three types of hazards, so it is important to understand them because they have different solutions that will avoid running into those hazards.
In general, why they're called hazards because especially earlier on, it was not clear who was going to take care of these issues.
They can be addressed by either a compiler or the pipeline processor designer, but somebody has to take care of these hazards.
If nobody does, the processor doesn't work or even worse, works most of the time but fails from time to time and it's really difficult to find out when and why it fails.
So as I said, there are three types of hazards that we can encounter and those are structural hazards, data hazards, and control hazards.
It is always a situation that prevents starting a new instruction while there is another instruction that is in flight.
Structural all hazards appear because of contention over a resource.
In most modern processors, at least these that are not that complicated like the ones that we are designing in this class, we are rarely going to run into structural hazards.
And the pipeline is designed to match the ISA and ISA prevents the existence of these hazards. Then, the second type are data hazards.
Data hazards essentially exist because of the dependency between the instructions.
So if there is one instruction that is in flight that is going to write the result into the register file, the result, the following instruction cannot really depend, cannot work with the same operant that is before it gets written back into the register file,
otherwise we will be working with an incorrect value. We're going to talk a little bit more about that just in a bit. And finally, there is a control hazard.
Control hazards happen when you have branches.
If the following instruction that is being executed in the pipeline is following a branch — so if there is a branch in the pipeline and there is another instruction after that, that next instruction may be invalid if the branch ends up being taken.
So let's talk about structural hazards in a bit more of a detail.
The simplest type of structural hazard that we already addressed in our design even of a single-cycle CPU is the contention between incrementing the program counter and performing arithmetic operations and when addressing the memory.
For example, we could have made a mistake and left out the pc plus four adder and said, let's use the ALU instead.
So every time we would have to add pc plus four to our instruction, we would use the ALU. Well, we have an issue there.
Every time we need to add four to a problem encounter, our ALU would not be available. So our processor would not work very well.
It would first, in one cycle, would add pc plus four. And then in the next cycle it would have to execute things.
So it was a very natural decision and we just went through that to have a dedicated adder that increments the program counter.
So in general, structural hazards appear because two instructions in the pipeline compete for the same resource. There are two ways to address structural hazards.
One is to stall, and that's what I've just described as a possible outcome for not having a pc plus four adder.
Essentially, the next instruction would stall until the previous instruction is finished using that resource.
A stall often means introducing knobs. We'll see that in a bit.
A more common solution is to add more hardware to our pipeline such that all instructions can execute concurrently.
So let's take a look at a fairly straightforward structural hazards that can exist because of the register file.
So in RISC-V ISA, our instructions can access the registered file three times. There are two operants to be read and one to be written.
So our register file has to be able to support that, otherwise we would have a shortage of resources.
So our register file is designed to have two read ports and a write port. There are, remember, three addresses that go into the input of the register file.
There is another subtlety in there.
In order to be able to complete all of this all of the operations in a single cycle or in a pipeline processor, we made one the assumption that the register file is fairly fast.
So it is faster than many of the other units that we have in the processor.
We can read the register file in 100 picoseconds and we can also write to a register file in 100 picoseconds.
We'll see that that's a convenient thing that allows us to both read and write the register file in a single cycle.
But the key thing here is registered file has to be designed to support three accesses per cycle simultaneously. Let's take a look at another type of a structural hazard that we may have.
There may be a memory contention.
So in pretty much every instruction needs to access the instruction memory but some instructions need to read or write the data to the memory.
And we said that we have this unified concept of a memory that we are working with a store program computer so there should be just one memory.
So every time there is a load or store, it is going to contend with every other instruction for the memory access.
In this case, it is shown that if you have a load word during the memory access phase, another instruction that would perhaps be trying to read an instruction if you just said one memory, this add immediate would have to stall and will have to wait until the load word is
done if we just had one memory. So a solution to this is to have two memories. But didn't you just contradict yourself, Borivoje?
Don't we have just one memory? And what's the story about two memories?
Well, we do have one main memory that lives in DRAM, but we generally have cache that is on our processor chip.
And you're going to see that in just next module in a couple of lectures.
Essentially, there are chunks of memory on our processor chip that have copies of the instructions that have been copied from the main memory and copies of the data that has been copied from the main memory with two separate ways to access it.
So we don't have to contend for the main memory when we are fetching instruction while another instruction is completing a read or a write.
So in summary, structural hazards can exist but they are avoided typically by the hardware design that matches the ISA.
So we look through all the instructions that are in the ISA and we make sure that our hardware is provisioned to support all of these instructions during the depth of the pipeline that can exist concurrently during the depths of a pipeline.
So what we have seen is that our register file has to support whatever the ISA requires us to have for it and that we need to have separate the instruction and data memories or at least copies of instruction and data memory so we can access them separately.
That's it for structural hazards. They're relatively straightforward to understand. The next ones are data hazards, which are a little bit trickier. See you in a bit.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.