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, and welcome back to our discussion about input/output devices.
We've seen that we often deal with a variety of devices, and they usually work with very different data rates.
Some of them are very slow and some of them can be producing a lot of data that processor will need to keep up with.
We also have seen that, generally, the way how we work with these devices is by talking to its memory mapped registers, their memory mapped registers.
So they have two types of registers, or at the minimum, one of each type. There would be a control register and a data register.
These control registers would basically tell us whether it's OK to read or write the data to the device.
We can use an analogy of flag on the road that tells us whether it's OK or not to go through the part of the road.
If they have a raised flag, that means that we should generally stop, and then if they drop that flag, then it's OK to go.
Similarly, that's how the control register tells us whether the device is ready to receive the data if we are writing to it or it has the data ready for the processor to read from.
So where is the data that should be read from, that's in the data register, it's also the register that we are going to write to.
So in a procedure called polling, a processor repeatedly and periodically checks the control register, and there is usually one bit over there that is a ready bit.
The ready bit means that either the device is ready to receive the data, or it has some data that is ready to be sent to the processor.
That ready signal is typically a single bit, and it is controlled by the device. The device sets it by changing its value from 0 to 1.
Processor then will load from the device or write to the device, whether it's an input or output device.
And the I/O device resets the control signal from 1 to 0. As we said, this a procedure called polling.
So let's see an example of a polling code. This is, by the way, the simplest method that we can use to work with input/output devices.
So in this example, we have a memory map that contains one input device and one output device, and each of these devices just has one control and one data register, and so input device is one input control register and one data register, and output devices one control register, one data register.
So here are two loops, one for working with the input device, the other one that conversely works with the output device.
Conveniently, the first entry into the memory map is set to be value 7ffff00, last three digits being zeros, make it convenient to use a lui to load that address into the temporary register, and we don't have to follow it with another immediate.
So then we enter this loop.
The loop essentially loads the value from the control register — input control register — and checks whether the ready bet has been asserted and whether it's equal to 1.
It's going to stay in this loop as long as that is equal to 0 and immediate is going to produce a value of 0, unless the ready bit, which is the least significant bit in this register, is asserted.
If it is, it will exit the loop and load the data. I'll do whatever it needs to do with the data and continue polling at some point.
And the output polling works exactly the same way. We would like to, for example, to display from a1.
While we are again, going to lui, we are going to enter the waitloop, now, we are going to check the appropriate registers, and we are going to write to it when the device is ready.
So this is very simple and convenient, but it's not always the most efficient way of dealing with I/O devices.
So let's assume our standard processor that we have been dealing with that runs at 1 gigahertz clock rate.
So let's say that it takes 400 clock cycles for appalling operation, so we call a polling routine, check the device, whether it's a keyboard or Wi-Fi, whether it's ready to send us the data or receive it, and then return.
So how much of a time, what percentage of its clock cycles does the processor need to spend on polling?
So let's take a look at the simple example, usually mouse needs to be polled something like 30 times per second in order to avoid jittery motions on the screen.
So let's see. What's our cost of polling a mouse to see if it has changed its data, if it has changed its location.
So when we are polling a mouse, let's say we said that we need 30 polls per second, and each poll takes 400 clocks to complete. So that's 12,000 clocks per second.
So if processor is polling a mouse, then that's a really tiny fraction of the total clock cycles that are available in each second.
So we divide this number of 12 K with a billion clock cycles, so that is 0.001%. So that's fine.
That's not a big load for a processor. A processor can poll that kind of an input device.
However, it's not practical if you're pulling all of the devices and we don't know when to stop polling for a polling mouse.
If we know that somebody — if there is not going to be mouse activity. But it's fine for now. Let's take a look at a different device.
The device that has a lot more data. For example, if you would like to pull a disk, and the disk let's say is moderately fast.
One that is capable of producing 16 megabits per second and we need to do 16 bytes per poll, so we need 1 million polls per second.
So how many cycles do we need to spend on that? What's the percentage of cycles, so we need to do 1 million polls per second.
It's going to cost us, again, 400 cycles to do each poll, so that's 400 million clocks per second that we would spend on polling the disk.
Well, we only have a billion cycles per second. That basically means that this processor will be doing nothing else than polling.
40% of clock cycles basically would render that processor. Won't be able to do much other things.
And by the way, also polling disks that produce a lot of data in larger chunks, polling them to receive small chunks doesn't really make that much sense.
So trying to get 16 bytes per poll may not be the best way of doing things.
So we need to come up with a better way of working with these devices that can produce a lot of data, and what we'll find out when we discover that will most likely use that better mechanism for everything else.
We'll get to that after a quick break. See you then.
Đă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.