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ả.
[MUSIC PLAYING] PROFESSOR: Hello.
Welcome back to our module on pipelining a RISC-V processor. We're quite proud when we designed the functional RISC-V processor. And that was quite an accomplishment.
But I have to tell you a secret. In practice, nobody uses single-cycle CPUs. There were some, early on, single-cycle CPUs.
But they, basically, have been abandoned over time. Why? Because they're generally inefficient. Not every instruction uses every stage.
And single-cycle CPU really is — has a cycle that is set by executing all five stages of processing. So what do people do?
They do pipelining. And the reasons are very similar and the mechanism is very similar to what we have seen in laundry processing.
In laundry processing, we saw that there are four stages of processing — washing, drying, folding, and stashing.
And generally, when there are multiple people who need to do the laundry, there are multiple laundry tasks that need to be performed.
Nobody really has to wait for each task to complete to go through all four stages of laundry processing before we start the next one.
We generally will go ahead and load the washer immediately after first task is done with that. And then we'll proceed, as we have seen before.
The same happens in processors.
Like laundry processing, data processing and processors has, so far, five stages — instruction fetch, instruction decode with register read, ALU, or execute stage, memory access, and write back.
And in our example, we have put some times that represent — that are reasonable representatives of how long does it take. We said the instruction fetch phase — 200 picoseconds.
Registry takes 100, ALU takes 200 picoseconds, and memory takes 200 picoseconds. Finally, register write is the same as register read, about 100 picoseconds.
Notice that registry read and register write are shorter than the others. It has significance. We are going to come back to that later.
So the entire — executing the entire instruction is a sum of this, all of these stages.
The time to execute the instruction equals the time to go through all of these stages. And that is 800 picoseconds.
We're also using a pictogram here that you'll find in the textbook, in our textbook and in some other textbooks, that is trying to illustrate what is active.
So when this box that represents a memory is shaded only half and when it is shaded on the right-hand side, it says that we are reading from that block.
So when we are reading from the registers, we are also shading the right-hand side.
On the other hand, when we would like to write to the memory, we will shade the left-hand side of the block, and so we would do during the register write back cycle with the registers.
On the other hand, when the ALU is active, we shade the whole thing.
So let's take a look at our silly way, or how does the single-cycle CPU process data.
So here is a string of instructions, instruction sequence that we would like to process, and there are a few of them. So let's say we first run into an "add."
We are going to run through an "add" as a — in single-cycle, we'll process all five stages.
We'll fetch the instruction, decode it, access the registers, perform the addition operation that we figured out during the decode process. We don't need to do anything with the memory.
But we are still going to wait for that time to pass. Then finally, we'll write back.
And then when we are done with all of that, we'll do the next instruction, which is the "or."
And when the "or" is done with writing back, we'll start the third instruction, which is "shift left logical." This is wasteful, as we have seen in the laundry example.
So we can do better. How do we do better? Well, we are going to pipeline. We don't have to wait for the entire inspection to complete to start the next instruction.
We just have to free up — to wait for the first resource to free up, which is an instruction memory.
As soon as we are done with reading the "add" out of the instruction memory, even though we don't it is "add" yet. It's just we have read 32 bits.
We can go ahead and start reading the next 32 bits. We'll read "or" and we'll start that "or" immediately after we are done reading the "add."
So two things are going to happen concurrently. We'll decode the "add" instruction and fetch the "or" instruction.
And as soon as we are done with the "or" instruction, reading of the "or" instruction, we can go on to the third one, "shift left logical."
So while we are reading "shift left logical" from the memory and we have no idea that it's "shift left logical," we will be accessing the registers for the "or" instructions and performing the addition of the — for the first "add" instruction.
Notice that one thing had to happen here. We had to separate these stages with registers, so-called pipeline registers.
Otherwise, all the data would get mixed up.
So what we are seeing here is that these instructions are being processed concurrently, and each instruction is in a different stage of execution.
So our clock cycle is there to transfer us between these stages of execution or move the data between the pipeline stages. It is not associated with processing of the entire instruction.
So this cycle is a lot shorter. It's one-fifth of the time that it takes us to process the entire instruction. We'll see more of that in a second.
So there is another really important thing. Compared to a single-cycle CPU, the time to process the entire instruction is now longer.
And it is longer for the reason that we have to set the clock cycle to match the slowest stage in the pipeline. What does that mean?
Well, that means that we have — had these imbalanced stages in the pipeline. Some of them were taking 200 picoseconds. Some of them were taking 100 picoseconds.
Now, since we are using one clock to clock them all, we have to set that clock period to be 200 picoseconds.
Otherwise, if it is shorter than that, some of these stages would not be completing their operation. So T cycle for a pipeline processor is 200 picoseconds.
That's a lot shorter. That is one quarter of what we have had for a single-cycle CPU, which was 800 picoseconds.
But the time to execute the entire instruction is 1,000 picoseconds. So it is longer.
So we lose on the latency of the single instruction, but we gain dramatically on the throughput.
Let's take a look at the — bit of a comparison between the single-cycle and pipeline instructions. Most that is in this — most of the things that are in this table are fairly logical.
And we should have seen them and noticed them already. The timing per stage or per step varies in single-cycle.
It is fixed for all pipeline ones because register access is only 100 picoseconds. And in pipeline, they all have to be made to be the same length.
The CPI, Cycles Per Instruction, ideally is set to 1. In practice, if you have any memory misses, we'll need more than one cycle per instruction, depending how good is our memory system.
We'll deal with that in great detail a bit later. In practice, pipeline systems allow us to have multiple execution units. I'll mention that briefly later.
But it allows us to actually bring the CPI below 1. That is not the subject of this class. It is a subject of CS 152.
Now, what we have seen the clock rate here — was 1 over 800 picoseconds, or 1.25 gigahertz. Pipeline processor can run at 5 gigahertz and achieve a 4x speed-up.
So in summary, the instruction time, the time to execute an instruction, gets a little bit longer. But we get a dramatic improvement in throughput because we get dramatically higher clock speed.
Remember, our increase in throughput is not equal to the number of stages that we have. Theoretically, we could have 5x increase in throughput.
But since the stages had imbalance delays, we lost a little bit. We still got a good increase of 4x. And that is the reason why people always design pipeline processors.
As we'll see, the design process is not logical and not much more complex than the single-cycle pipeline. So why not do it?
Let's take a look, at the moment, what is happening sequentially and what is happening simultaneously when we are executing these instructions. So we have a list here of six instructions.
And notice that the coloring here is showing that the "add" instruction is not accessing the memory. "Or" instruction is not accessing the data memory.
"Shift left logical" — neither that one is accessing the memory. But "store word" is writing into memory. So the left-hand side is colored. "Load word" is reading from the memory.
So the right-hand side is shaded. And "add immediate" is not accessing the memory.
There is not much to add to here. This is the time to execute the instruction. It's 1,000 picoseconds, or 1 nanosecond. And the cycle time is one-fifth of that, or 200 picoseconds.
Now, when we would like to know what is happening here in — sequentially, it is the usage of resources in the pipeline or stages in the pipeline by one instruction.
Resource use of instruction is sequential in time. Each instruction goes through the fetch, decode, and register access, execution phase, memory access, and write back.
On the other hand, multiple instructions are using different resources at the same time.
So there are five instructions here that we will say, in flight, that are using different resources because they're available. So these resources here — the first instruction is near its completion.
So "add" is writing back the result into t0. "Or" is in data access stage. It's not doing anything.
It's basically just waiting for the "add" to be done so it can write back its result in t3. "Shift left logical" is using the ALU to perform the shift.
"Store word" is, essentially, fetching the t3 and t0 values from the t3 and t0 register such that it can use them.
And the store operation "load word" is just being fetched from the memory. And we don't even know that it's a load.
And that's it that we have to — what we need to know for now, conceptually, about the pipelining of RISC-V processor. It is very similar to running laundry.
We're going to see what — in the next module what we need to do with our data path to support that. So see you then after a bit of a break.
Đă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.