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ả.
[PIANO MUSIC PLAYING] PROFESSOR: Hello, and welcome back to our discussion about input output.
So we have seen two mechanisms for working with input output devices so far. We have seen polling of devices and interrupts.
Interrupts are actually being practically used for the devices that don't generate a lot of data and don't consume a lot of data.
Those that consume a lot of data are generally, nowadays, based on direct memory access. So that's a different mechanism. And let's introduce it here.
So far, the only device that was able to control data transfers to the main memory was the processor itself.
In order to offload the processor so it doesn't spend a lot of time handling these loads and stores, we need to come up with a new device that is new piece of hardware that is going to help processor move large chunks of data to and from the main memory.
So the DMA engine may exist on the same die as our processor, but it will operate, it will take control over the memory channels under supervision from the CPU.
So essentially what is going to happen here is the DMA engine will work independently.
It has some registers that are written by the CPU, you know, perhaps memory mapped.
And these registers are going to contain the memory addresses to place the data, the number of bytes to be transferred, the number of the I/O device that is supposed to do that direction of the transfer to the memory or from the memory, and the units of transfer, and how much
should they do per burst because it can do multiple bursts of certain duration per transfer.
So to illustrate how does that work, here is a picture from a textbook that we can use.
So the CPU is the one that will initiate the transfer, whether it is going to the memory or from the memory.
It will write the address, the count, and control bits into the DMA controller.
In turn, the DMA will request transfer to the memory from the device, perhaps.
Somebody who generally has plenty of data to move around is the disk or the disk controller that may be controlling multiple disks.
So disks, modern disks, generally have buffers, and they can read ahead and buffer some amount of data, non-negligible amount of data, on them.
So DMA engine is going to tell it, basically, to transfer the contents of its buffer to a particular location in a memory that has been specified by the CPU.
When it is done with a transfer, this controller will send an acknowledgment to a DMA engine, and DMA engine will interrupt the CPU to tell that it is done, the file has been moved and the transfer has been completed.
So the CPU gets interrupted only twice. First, to start the transfer. Then, the transfer may be long.
We may be moving megabytes or gigabytes of data, which is what I generally do with when moving these videos back and forth.
And then, while the data is moving, the CPU can do something else.
And then when it's done, it gets interrupted again to just know that the file movement has completed.
All right, let's step through that for the incoming direction of the data. So the processor will receive the interrupt from the device.
It would take the interrupt through a trap handler. It would initiate the transfer.
It would instruct the DMA engine to place data at certain addresses in the memory. The device and the DMA engine are going to handle the transfer themselves.
CPU is free to continue executing a program, returns from the interrupt and continues doing whatever it has been doing.
Upon completion, the device, the disk in this case, and the DMA engine interrupt the CPU again.
Generally a device acknowledges to the DMA controller, and DMA controller interrupts the CPU to tell that it is done.
In the outgoing direction of the data, if CPU has something that would like to move from memory to an external device, it initiates the transfer.
First, it confirms that the device is ready by reading its control register, and then begins the transfer. Probably more properly we would say here initiates the transfer.
It instructs the DMA engine to work with the device to tell it that the data is available at a certain address in the memory.
And then the DMA is going to work with the device, say a disk, to handle the transfer. CPU does whatever it wanted to do next.
And the device acknowledges that it has received the data to the DMA engine, which interrupts the CPU to signal the completion.
That is it. That sounds fairly simple and cool. These things did, you know, we mentioned that we had programmed I/O as a mode of operation say, in the '90s, with 88 disks.
DMA has replaced that. In 2000s, most of the disks nowadays, or all of the disk nowadays, do support DMA transfers.
But there are some other problems. These DMA controllers that share the chip area with the processor, we have freedom where we would like to plug them in.
So where do we want to put our DMA controller in the memory hierarchy? Well, there are two extremes and many other variants. First, we can put it between the CPU and L1 cache.
So we can plug it in right there. If we do that, we got free coherency, meaning the processor memory system, cache system, is going to handle the coherency.
The problem here is that every time we initiate the DMA transfer, we're going to trash the CPU's working set with transfer data.
The other option is to put it between the last-level cache and the main memory so we don't mess processor caches.
Processor on the interrupt can just, after handling the interrupt it can resume what it was doing.
But the challenge here is that we need to implement a new coherency engine, and that is usually what is being done.
Somehow the DMA has to work with the coherency engine to support it.
That's it for the DMA and for generally handling I/O devices. Just one more quick example is coming up, and then we are done with this module. See you after a quick 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.