[CS61C FA20] Lecture 31.2 - I/O: I/O Polling — Transcript
Full transcript
- 0:09Hello and welcome back to our discussion
- 0:12about input output devices.
- 0:15We have seen that we often deal with a
- 0:17variety of devices and they usually work
- 0:19with very different data rates. Some of
- 0:21them are very slow and some of them can
- 0:24be producing a lot of data that
- 0:26processor will need to keep up with.
- 0:30We also have seen that generally the way
- 0:34how we work with these devices is
- 0:37by
- 0:38talking to its memory mapped registers,
- 0:41their memory mapped registers. So they
- 0:43have
- 0:44two types of registers or at the minimum
- 0:48one of each type. Um there would be a
- 0:50control register and a data register.
- 0:55They these control registers would
- 0:59basically only tell us whether it's okay
- 1:01to read or write the data to the device.
- 1:05Um we can
- 1:08use an analogy of a a flagman on the
- 1:11road that tells us whether it's okay or
- 1:13not to go through the draw part of the
- 1:15road. If they have a
- 1:18a raised flag, that means that we should
- 1:21generally stop and then if they
- 1:24drop that flag, then it's okay to to go.
- 1:31Similarly, that's how the control
- 1:34register tells us whether the device is
- 1:36ready to receive the data if we're
- 1:38writing to it or it has the data ready
- 1:41for the processor to read from. So where
- 1:44is the data that should be read from?
- 1:46That's in the data register. It's also
- 1:48the register that we're going to write
- 1:50to.
- 1:52So in a procedure called polling,
- 1:56a processor
- 1:57repeatedly or and periodically checks
- 2:01the control register.
- 2:04And there is usually one bit over there
- 2:07that is a ready bit. The ready bit means
- 2:10that either the device is ready to
- 2:14receive the data or it has some data
- 2:17that is ready to be sent to the
- 2:18processor.
- 2:20That ready signal is typically a single
- 2:22bit and it is controlled by the device.
- 2:26The device um sets it by changing its
- 2:29value from zero to one.
- 2:33The processor then will load from the
- 2:37device or write to the device, whether
- 2:40it's an input or output device.
- 2:43And the IO device
- 2:45um resets the control signal from one to
- 2:49zero.
- 2:50As we said, this is a procedure called
- 2:52polling.
- 2:54So, let's see
- 2:55uh an example of a polling code.
- 2:58This is, by the way, the simplest
- 3:00procedure
- 3:01simple simplest method that we will work
- 3:04that we can use to work with
- 3:06input-output devices.
- 3:08So, in this example, we have a memory
- 3:11map that contains one input device and
- 3:14one output device and each of these
- 3:16devices just has one control and one
- 3:18data register. And as so, input device
- 3:22has one input control register and one
- 3:25data register and output device has one
- 3:27control register, one data register.
- 3:29So, here are two loops.
- 3:31One
- 3:32for working with input device, the other
- 3:34one that conversely works with the
- 3:36output device.
- 3:38Um
- 3:39conveniently, the first
- 3:42entry into the memory map is set to be a
- 3:45value 7 FFFFF000.
- 3:48Last three digits being zeros
- 3:51uh make it convenient to use a lui
- 3:53to load that address into the temporary
- 3:56register and we don't have to follow it
- 3:58with an add immediate.
- 4:01So, then we enter this loop. The loop
- 4:05essentially loads the value from the
- 4:07control register,
- 4:09uh input control register, and checks
- 4:12whether the ready bit has been asserted,
- 4:15whether it's equal to one.
- 4:17It's going to stay in this loop as long
- 4:19as that is equal to zero. This end
- 4:22immediate is going to to to keep, you
- 4:25know, is is going to produce a a value
- 4:28of zero unless the ready bit, which is
- 4:32the least significant bit in this
- 4:35register, is asserted. If it is, it will
- 4:38exit the loop and load the data. I'll do
- 4:42whatever it needs to do with the data
- 4:44and continue polling at some point.
- 4:49The output
- 4:52polling works exactly the same way. We
- 4:55would like to, for example, write to
- 4:57display from A1. Well, we are again
- 5:01going to Louie. We are going to
- 5:04enter the wait loop. Now, we are going
- 5:06to check the appropriate registers, and
- 5:08we are going to
- 5:10write to it when the device is ready.
- 5:17So, this is very simple and convenient,
- 5:20but it's not always the most efficient
- 5:23way of dealing with IO devices. So,
- 5:24let's assume our standard processor that
- 5:27we have dealing we have been dealing
- 5:28with that runs at 1 GHz at its uh clock
- 5:31rate.
- 5:32So, let's say that it takes 400 clock
- 5:34cycles for a polling operation. So, we
- 5:37call a polling routine, you know, check
- 5:39the device whether it's a keyboard or
- 5:41Wi-Fi, um you know, whether it's uh
- 5:44ready to to send us the data or receive
- 5:47it, and then return. So, how much of a
- 5:50time, what percentage of its clock
- 5:53cycles does the processor need to spend
- 5:55on polling?
- 5:56So, let's take a look at the simple
- 5:58example. Usually, mouse needs to be
- 6:00polled something like 30 times per
- 6:02second in order to avoid jittery motions
- 6:05on the screen.
- 6:06Um
- 6:08So, let's see. What's our cost of
- 6:10polling the the
- 6:13polling a mouse to see if it has changed
- 6:16its state, if it has changed its
- 6:17location.
- 6:19So, when we're polling a mouse, let's
- 6:22say uh we said that we need 30 polls per
- 6:24second, and each poll takes 400 clocks
- 6:28to complete. So, that's 12,000 clocks
- 6:32per second.
- 6:34So, if processor is polling a mouse,
- 6:36then that's a really tiny fraction of
- 6:40the total clock clock cycles that are
- 6:43being that are available in each second.
- 6:45So, we divide this number of 12K
- 6:49with a billion clock cycles. So, that is
- 6:510.001%.
- 6:55So,
- 6:57that's fine.
- 6:58Um that that's not a big load for a
- 7:00processor, and processor can poll that
- 7:02kind of an
- 7:03um input device. However, it's kind of
- 7:05not practical if you are polling all of
- 7:07the devices, and we don't know when to
- 7:09stop polling for a polling mouse. You
- 7:12know, if we know that somebody if
- 7:14there's not not going to be a mouse
- 7:16activity.
- 7:17But, it's fine for now.
- 7:19Um
- 7:21Let's take a look at a different device,
- 7:22a device that has a lot more data. For
- 7:24example, um if you would like to poll a
- 7:27disk, and a disk, let's say, is um
- 7:30moderately fast, one that is capable of
- 7:32producing 16 MB per second. Um and it we
- 7:37need to do uh 16 bytes per poll. So, we
- 7:42need 1 million polls per second.
- 7:45So, how
- 7:47um how do we um
- 7:50you know, how how many cycles do we need
- 7:52to to spend on that? What's the
- 7:53percentage of cycles? So, we need to do
- 7:551 million polls per second. It's going
- 7:57to cost us again 400 cycles to um do
- 8:01each poll. So, that's a 400 million
- 8:04uh clocks per second that we would spend
- 8:08on polling the disk.
- 8:09Well,
- 8:11we only have a billion
- 8:12cycles per second. That basically means
- 8:15that this processor will be doing
- 8:18nothing else than polling. 40% of clock
- 8:21cycles basically would render
- 8:25that processor not be able to do much
- 8:28other things. And by the way, also
- 8:30polling disks that produce a lot of data
- 8:33in larger chunks, polling them to
- 8:35receive small chunks doesn't really make
- 8:38that much sense. So, trying to get 16
- 8:41bytes per poll may not be the best way
- 8:44of doing things.
- 8:46So, we need to come up with a better way
- 8:49of working with these devices that can
- 8:50produce a lot of data. And what we'll
- 8:52find out when we discover that, we'll
- 8:55most likely use that better mechanism
- 8:57for everything else.
- 8:59We'll get to that after a quick break.
- 9:01See you then.
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 31.2 - I/O: I/O Polling by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,290 words across 207 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 choose a caption track available on the video.
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, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.