YouTube2Text

[CS61C FA20] Lecture 31.2 - I/O: I/O Polling — Transcript

by CS 61C Departmental · 1,274 words · 223 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:09hello
  3. 0:10and welcome back to our discussion about
  4. 0:12input
  5. 0:13output devices we've seen that we often
  6. 0:16deal with a variety of devices
  7. 0:18and they usually work with very
  8. 0:20different data rates some of them are
  9. 0:22very slow
  10. 0:23and some of them can be producing a lot
  11. 0:25of data that
  12. 0:26processor will need to keep up with
  13. 0:30we also have seen that generally the way
  14. 0:34how we work with these devices is
  15. 0:37by talking to its memory mapped
  16. 0:40registers their memory map registers
  17. 0:42so they have two types of registers
  18. 0:47or at the minimum one of each type
  19. 0:50there would be a control register and a
  20. 0:52data register
  21. 0:56the these control registers
  22. 0:59would basically tell us whether it's
  23. 1:00okay to read
  24. 1:02or write the data to the device um
  25. 1:06we can use an analogy of a
  26. 1:10flagman on the road that tells us
  27. 1:12whether it's okay or not
  28. 1:13to go through the draw part of the road
  29. 1:16if they have a
  30. 1:18raised flag that means that we should
  31. 1:21generally stop
  32. 1:23and then if they uh drop that flag then
  33. 1:26it's okay to to go
  34. 1:31similarly that's how the control
  35. 1:34register tells us whether
  36. 1:35the device is ready to receive the data
  37. 1:38if we're writing to it
  38. 1:39or it has the data ready for the
  39. 1:41processor to read from
  40. 1:43so where is the data that should be read
  41. 1:46from that's in the data register
  42. 1:48it's also the register that we are going
  43. 1:50to write to
  44. 1:52so in a procedure called polling
  45. 1:56a processor repeatedly or and
  46. 1:59periodically
  47. 2:00checks the control register
  48. 2:04and there is usually one bit over there
  49. 2:08that is a ready bit ready bit means that
  50. 2:11either
  51. 2:11the device is ready to receive the data
  52. 2:15or it has some data that is ready to be
  53. 2:17sent to the processor
  54. 2:20at ready signal is typically a single
  55. 2:22bit
  56. 2:23and it is controlled by the device
  57. 2:26the device sets it by changing its value
  58. 2:29from zero to one
  59. 2:34processor then will load from
  60. 2:37the device or right to the device
  61. 2:40whether it's an input or output device
  62. 2:43and the io device
  63. 2:46resets the control signal from one to
  64. 2:49zero
  65. 2:50as we said this is a procedure called
  66. 2:52polling
  67. 2:54so let's see uh an example of a polling
  68. 2:57code
  69. 2:58this is by the way the simplest
  70. 3:00procedure car you know
  71. 3:02simplest method that we will work that
  72. 3:04we can use
  73. 3:05to work with input output devices
  74. 3:08so in this example we have a memory map
  75. 3:11that contains
  76. 3:13one input device and one output device
  77. 3:15and each of these devices just as one
  78. 3:17control and one data register and as
  79. 3:21so input devices one input control
  80. 3:24register
  81. 3:24and one data register and output devices
  82. 3:27one control register one data register
  83. 3:29so here are two loops one for
  84. 3:33working with input device the other one
  85. 3:35that conversely works with the output
  86. 3:36device
  87. 3:39conveniently the first
  88. 3:42entry into the memory map is set to be a
  89. 3:45value
  90. 3:46seven ffff000 last three digits being
  91. 3:49zeros
  92. 3:51make it convenient to use a louie to
  93. 3:54load that address into the temporary
  94. 3:56register and we don't have to follow it
  95. 3:58with
  96. 3:58an ad immediate so then we enter
  97. 4:03this loop the loop essentially loads the
  98. 4:06value
  99. 4:07from the control register input control
  100. 4:10register
  101. 4:11and checks whether the ready bit is has
  102. 4:14been asserted
  103. 4:15whether it's equal to one it is going to
  104. 4:18stay in this loop
  105. 4:19as long as that is equal to zero this
  106. 4:22end immediate is going to
  107. 4:23to to keep you know is is going to
  108. 4:26produce a
  109. 4:28value of 0 unless
  110. 4:31the ready bit which is the least
  111. 4:33significant bit in this register
  112. 4:35is asserted if it is it will exit the
  113. 4:38loop
  114. 4:39and load the data i'll do whatever
  115. 4:42it needs to do with the data and
  116. 4:44continue polling
  117. 4:45at some point
  118. 4:50the output polling works exactly the
  119. 4:53same way
  120. 4:54we would like to for example write to
  121. 4:57a display from a1 while
  122. 5:00we are again going to luay we are going
  123. 5:03to
  124. 5:04enter a weight loop now we are going to
  125. 5:06check the appropriate registers
  126. 5:07and we are going to write to it
  127. 5:11when the device is ready
  128. 5:17so this is very simple and convenient
  129. 5:20but is not always the most efficient way
  130. 5:23of dealing with io devices so let's
  131. 5:25assume
  132. 5:25our standard processor that we have
  133. 5:27dealing we have been dealing with that
  134. 5:29runs at one gigahertz
  135. 5:30clock rate so let's say that it takes
  136. 5:33400 clock cycles for a polling operation
  137. 5:36so we call a polling routine you know
  138. 5:39check the device whether it's a keyboard
  139. 5:40or wi-fi um you know whether it's uh
  140. 5:44ready to to send us the data or receive
  141. 5:47it
  142. 5:47and then return so how much of a time
  143. 5:51what percentage of its clock cycles does
  144. 5:53the processor need to spend on polling
  145. 5:56so let's take a look at a simple example
  146. 5:58usually mouse needs to be pulled
  147. 6:00something like 30 times per second in
  148. 6:02order to avoid
  149. 6:04jittery motions on the screen um
  150. 6:08so let's see what's our cost of polling
  151. 6:11the
  152. 6:12the polling amounts to see if it has
  153. 6:15changed this data if it has changed its
  154. 6:17location
  155. 6:19so when we're pulling a mouse let's say
  156. 6:22we said that we need 30 poles per second
  157. 6:24each pole takes
  158. 6:26400 clocks to complete
  159. 6:29so that's 12 000 clocks per second
  160. 6:34so if processor is pulling a mouse then
  161. 6:37that's a really tiny fraction of the
  162. 6:40total clock clock cycles that are being
  163. 6:44they're available in each second so we
  164. 6:46divide this number of 12
  165. 6:48k with a billion clock cycles though
  166. 6:51that is 0.001
  167. 6:55so that's fine
  168. 6:58um that that's not a big load for a
  169. 7:00processor and processor can pull that
  170. 7:02kind of an
  171. 7:03input device however it's kind of not
  172. 7:05practical if we are pulling all of the
  173. 7:07devices and we don't know when to stop
  174. 7:09pulling for a polling mouse you know if
  175. 7:12we know that somebody
  176. 7:14if there is no not going to be mouse
  177. 7:16activity
  178. 7:17but it's fine for now um
  179. 7:21let's take a look at a different device
  180. 7:22the device that has a lot more data for
  181. 7:24example
  182. 7:25um if you would like to pull a disk and
  183. 7:27the disk
  184. 7:28let's say is a moderately fast one that
  185. 7:32is capable of producing 16 megabytes per
  186. 7:34second
  187. 7:35and it we need to
  188. 7:39do 16 bytes per pole so
  189. 7:42we need 1 million pulse per second
  190. 7:45so how um how do we
  191. 7:49um you know how how many cycles do we
  192. 7:51need to spend on that what's the
  193. 7:53percentage of cycles
  194. 7:54so we need to do one million poles per
  195. 7:56second it's going to cost us again
  196. 7:58400 cycles to do each poll so that's a
  197. 8:02400 million
  198. 8:05clocks per second that we would spend on
  199. 8:08polling the disk
  200. 8:09well we only have a billion cycles
  201. 8:13per second that basically means that
  202. 8:16this processor
  203. 8:17will be doing nothing else than polling
  204. 8:2040
  205. 8:21of clock cycles basically would uh
  206. 8:24render that processor don't be able to
  207. 8:27do
  208. 8:28much other things and by the way also
  209. 8:30polling disks that
  210. 8:32produce a lot of data in larger chunks
  211. 8:34pulling them to receive small chunks
  212. 8:36doesn't really make that much sense
  213. 8:40so trying to get 16 bytes per pole
  214. 8:43may not be the best way of doing things
  215. 8:46so we need to come up with a better way
  216. 8:49of working with these devices that can
  217. 8:50produce
  218. 8:51a lot of data and what we'll find out
  219. 8:53when we discover that
  220. 8:54we'll most likely use that better
  221. 8:56mechanism for everything else
  222. 8:59we'll get to that after a quick break
  223. 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.