YouTube2Text

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

by CS 61C Departmental · 1,290 words · 207 segments · language en · Watch on YouTube

Full transcript

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