[CS61C FA20] Lecture 31.2 - I/O: I/O Polling — Transcript
Full transcript
- 0:00[Music]
- 0:09hello
- 0:10and welcome back to our discussion about
- 0:12input
- 0:13output devices we've seen that we often
- 0:16deal with a variety of devices
- 0:18and they usually work with very
- 0:20different data rates some of them are
- 0:22very slow
- 0:23and some of them can be producing a lot
- 0:25of 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 talking to its memory mapped
- 0:40registers their memory map registers
- 0:42so they have two types of registers
- 0:47or at the minimum one of each type
- 0:50there would be a control register and a
- 0:52data register
- 0:56the these control registers
- 0:59would basically tell us whether it's
- 1:00okay to read
- 1:02or write the data to the device um
- 1:06we can use an analogy of a
- 1:10flagman on the road that tells us
- 1:12whether it's okay or not
- 1:13to go through the draw part of the road
- 1:16if they have a
- 1:18raised flag that means that we should
- 1:21generally stop
- 1:23and then if they uh drop that flag then
- 1:26it's okay to to go
- 1:31similarly that's how the control
- 1:34register tells us whether
- 1:35the device is ready to receive the data
- 1:38if we're writing to it
- 1:39or it has the data ready for the
- 1:41processor to read from
- 1:43so where is the data that should be read
- 1:46from that's in the data register
- 1:48it's also the register that we are going
- 1:50to write to
- 1:52so in a procedure called polling
- 1:56a processor repeatedly or and
- 1:59periodically
- 2:00checks the control register
- 2:04and there is usually one bit over there
- 2:08that is a ready bit ready bit means that
- 2:11either
- 2:11the device is ready to receive the data
- 2:15or it has some data that is ready to be
- 2:17sent to the processor
- 2:20at ready signal is typically a single
- 2:22bit
- 2:23and it is controlled by the device
- 2:26the device sets it by changing its value
- 2:29from zero to one
- 2:34processor then will load from
- 2:37the device or right to the device
- 2:40whether it's an input or output device
- 2:43and the io device
- 2:46resets the control signal from one to
- 2:49zero
- 2:50as we said this is a procedure called
- 2:52polling
- 2:54so let's see uh an example of a polling
- 2:57code
- 2:58this is by the way the simplest
- 3:00procedure car you know
- 3:02simplest method that we will work that
- 3:04we can use
- 3:05to work with input output devices
- 3:08so in this example we have a memory map
- 3:11that contains
- 3:13one input device and one output device
- 3:15and each of these devices just as one
- 3:17control and one data register and as
- 3:21so input devices one input control
- 3:24register
- 3:24and one data register and output devices
- 3:27one control register one data register
- 3:29so here are two loops one for
- 3:33working with input device the other one
- 3:35that conversely works with the output
- 3:36device
- 3:39conveniently the first
- 3:42entry into the memory map is set to be a
- 3:45value
- 3:46seven ffff000 last three digits being
- 3:49zeros
- 3:51make it convenient to use a louie to
- 3:54load that address into the temporary
- 3:56register and we don't have to follow it
- 3:58with
- 3:58an ad immediate so then we enter
- 4:03this loop the loop essentially loads the
- 4:06value
- 4:07from the control register input control
- 4:10register
- 4:11and checks whether the ready bit is has
- 4:14been asserted
- 4:15whether it's equal to one it is going to
- 4:18stay in this loop
- 4:19as long as that is equal to zero this
- 4:22end immediate is going to
- 4:23to to keep you know is is going to
- 4:26produce a
- 4:28value of 0 unless
- 4:31the ready bit which is the least
- 4:33significant bit in this register
- 4:35is asserted if it is it will exit the
- 4:38loop
- 4:39and load the data i'll do whatever
- 4:42it needs to do with the data and
- 4:44continue polling
- 4:45at some point
- 4:50the output polling works exactly the
- 4:53same way
- 4:54we would like to for example write to
- 4:57a display from a1 while
- 5:00we are again going to luay we are going
- 5:03to
- 5:04enter a weight loop now we are going to
- 5:06check the appropriate registers
- 5:07and we are going to write to it
- 5:11when the device is ready
- 5:17so this is very simple and convenient
- 5:20but is not always the most efficient way
- 5:23of dealing with io devices so let's
- 5:25assume
- 5:25our standard processor that we have
- 5:27dealing we have been dealing with that
- 5:29runs at one gigahertz
- 5:30clock rate so let's say that it takes
- 5:33400 clock cycles for a polling operation
- 5:36so we call a polling routine you know
- 5:39check the device whether it's a keyboard
- 5:40or wi-fi um you know whether it's uh
- 5:44ready to to send us the data or receive
- 5:47it
- 5:47and then return so how much of a time
- 5:51what percentage of its clock cycles does
- 5:53the processor need to spend on polling
- 5:56so let's take a look at a simple example
- 5:58usually mouse needs to be pulled
- 6:00something like 30 times per second in
- 6:02order to avoid
- 6:04jittery motions on the screen um
- 6:08so let's see what's our cost of polling
- 6:11the
- 6:12the polling amounts to see if it has
- 6:15changed this data if it has changed its
- 6:17location
- 6:19so when we're pulling a mouse let's say
- 6:22we said that we need 30 poles per second
- 6:24each pole takes
- 6:26400 clocks to complete
- 6:29so that's 12 000 clocks per second
- 6:34so if processor is pulling a mouse then
- 6:37that's a really tiny fraction of the
- 6:40total clock clock cycles that are being
- 6:44they're available in each second so we
- 6:46divide this number of 12
- 6:48k with a billion clock cycles though
- 6:51that is 0.001
- 6:55so that's fine
- 6:58um that that's not a big load for a
- 7:00processor and processor can pull that
- 7:02kind of an
- 7:03input device however it's kind of not
- 7:05practical if we are pulling all of the
- 7:07devices and we don't know when to stop
- 7:09pulling for a polling mouse you know if
- 7:12we know that somebody
- 7:14if there is no not going to be mouse
- 7:16activity
- 7:17but it's fine for now um
- 7:21let's take a look at a different device
- 7:22the device that has a lot more data for
- 7:24example
- 7:25um if you would like to pull a disk and
- 7:27the disk
- 7:28let's say is a moderately fast one that
- 7:32is capable of producing 16 megabytes per
- 7:34second
- 7:35and it we need to
- 7:39do 16 bytes per pole so
- 7:42we need 1 million pulse per second
- 7:45so how um how do we
- 7:49um you know how how many cycles do we
- 7:51need to spend on that what's the
- 7:53percentage of cycles
- 7:54so we need to do one million poles per
- 7:56second it's going to cost us again
- 7:58400 cycles to do each poll so that's a
- 8:02400 million
- 8:05clocks per second that we would spend on
- 8:08polling the disk
- 8:09well we only have a billion cycles
- 8:13per second that basically means that
- 8:16this processor
- 8:17will be doing nothing else than polling
- 8:2040
- 8:21of clock cycles basically would uh
- 8:24render that processor don't be able to
- 8:27do
- 8:28much other things and by the way also
- 8:30polling disks that
- 8:32produce a lot of data in larger chunks
- 8:34pulling them to receive small chunks
- 8:36doesn't really make that much sense
- 8:40so trying to get 16 bytes per pole
- 8:43may not be the best way of doing things
- 8:46so we need to come up with a better way
- 8:49of working with these devices that can
- 8:50produce
- 8:51a lot of data and what we'll find out
- 8:53when we discover that
- 8:54we'll most likely use that better
- 8:56mechanism for 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,274 words across 223 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 translate the transcript into 100+ languages.
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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.