YouTube2Text

[CS61C FA20] Lecture 28.2 - OS & Virtual Memory Intro: Operating System Basics — Transcript

by CS 61C Departmental · 2,951 words · 531 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:10hello
  3. 0:11and welcome back to our discussion about
  4. 0:14operating systems as an introduction
  5. 0:17to dealing with the virtual memory
  6. 0:20so what we did so far we introduced the
  7. 0:23operating system
  8. 0:24as a big differentiator in our computing
  9. 0:28systems
  10. 0:29that is something that makes it possible
  11. 0:33to run instead of just one application
  12. 0:35at a time to run
  13. 0:36many of them and also to make many
  14. 0:39things
  15. 0:40around running that application a lot
  16. 0:43easier
  17. 0:46so let's dive a bit into
  18. 0:49what does the operating system do and
  19. 0:52how does it help us
  20. 0:55but also we're going to try to use it to
  21. 0:58justify the re the the needs for this
  22. 1:01concept of virtual memory
  23. 1:04okay so the first thing that we're going
  24. 1:06to take a look at
  25. 1:07is this just software component
  26. 1:11of the operating system it is softer but
  27. 1:14it is commonly
  28. 1:15a very large chunk of software often the
  29. 1:18most complex program that we have on our
  30. 1:21computers is the operating system so
  31. 1:24if we look at this
  32. 1:28there is this web website that kind of
  33. 1:31tries to compare
  34. 1:32how much of a code do we have in
  35. 1:34different kinds
  36. 1:36of applications or different kinds of
  37. 1:38systems so this starts
  38. 1:40yeah i think this was a snapshot around
  39. 1:422015-16 or so
  40. 1:45that is comparing the code base for
  41. 1:47different kinds of things
  42. 1:49so it starts with a simple iphone
  43. 1:52game app that you know can get by with
  44. 1:55like 10 000 lines of code
  45. 1:57perhaps a little bit more than a class
  46. 2:00project
  47. 2:00uh that you have seen then the early
  48. 2:04unix from the 70s also had about 10 000
  49. 2:07lines of code
  50. 2:08viruses around that size as well
  51. 2:13then as we go down through this you know
  52. 2:17space shuttle had 0.4 million lines of
  53. 2:21code
  54. 2:22um a lot more but not that that much
  55. 2:24more you have to be written in a very
  56. 2:26very compact way then you go down to
  57. 2:30other systems
  58. 2:32uh you know a million lines of code gets
  59. 2:34you
  60. 2:35quite a few interesting things for
  61. 2:37example in in order to encode to
  62. 2:38replicate the bacteria
  63. 2:40the amount of dna that it stores holds
  64. 2:44something that is an equivalent to 1.1
  65. 2:47um
  66. 2:48millions many million lines of code um
  67. 2:51f22 fighter jet 1.7 million lines of
  68. 2:54code
  69. 2:55uh linux kernel all linux kernel 2.2
  70. 2:58um is of the order of two million lines
  71. 3:02of code
  72. 3:03jurassic park was around that size
  73. 3:08that size as well as you go browse
  74. 3:10through this you will find some other
  75. 3:12interesting things
  76. 3:13uh f35 fighter jet had 24 million lines
  77. 3:16of code microsoft office
  78. 3:18back in 2001 had 25 million lines of
  79. 3:20code
  80. 3:22and that the other operating systems
  81. 3:25that we have here like windows xp
  82. 3:30had close to 15 million lines of code
  83. 3:33and so
  84. 3:33did microsoft office 2003.
  85. 3:37um going down we see
  86. 3:40more complex things nowadays you will
  87. 3:44find
  88. 3:45os down here mac likes
  89. 3:48older version 2016-ish version of mac os
  90. 3:52had over 80 million lines of code
  91. 3:55modern car software like a tesla even
  92. 3:58back then had 100 million lines of code
  93. 4:00in order to encode mars's genome that
  94. 4:03was equivalent to more than 100 million
  95. 4:06lines of code on the bottom the entire
  96. 4:08google's code
  97. 4:10base was 2 billion lines of code
  98. 4:14so while operating system while
  99. 4:16operating system is not
  100. 4:17as big as google's code base it is up
  101. 4:19there among
  102. 4:20the most complex things that we have
  103. 4:23built
  104. 4:26so back to to this
  105. 4:29um you know here this is a plot over
  106. 4:32many many years
  107. 4:33how did the code base for the linux grow
  108. 4:37um so the current uh versions in this
  109. 4:39plots
  110. 4:41this website plots it up to roughly
  111. 4:4420
  112. 4:4819 or so puts
  113. 4:51linux at about 20
  114. 4:55millions lines of code
  115. 4:58so what does what do these 20 millions
  116. 5:01of lines of code do
  117. 5:04a lot of useful things so os
  118. 5:08is almost the first thing that runs when
  119. 5:10the computer starts
  120. 5:12i'm going to go in a little bit more of
  121. 5:13a detail with that in
  122. 5:15just a second uh first thing is going to
  123. 5:18be something that
  124. 5:19is you know will be loaded is the bios
  125. 5:21and the bootloader but then after that
  126. 5:24we don't jump into applications we load
  127. 5:26the operating system
  128. 5:28then in next thing
  129. 5:31that it will do as soon as it finds
  130. 5:33itself comfortable
  131. 5:34inside your computer operating system is
  132. 5:36going to find all the devices they'll
  133. 5:38find out how many cores are there
  134. 5:40what kind of io devices do you have do
  135. 5:43you have a printer
  136. 5:44a display keyboard what kind of disks
  137. 5:47and so on
  138. 5:48and it is going to do something in linux
  139. 5:51world
  140. 5:52it will call it will build a device 3.
  141. 5:55and by using that we'll know what kind
  142. 5:58of resources we have
  143. 5:59and what kind of operating system
  144. 6:01functions we can use
  145. 6:02to access those devices that is often
  146. 6:05relied
  147. 6:06on to by by using hardware specific
  148. 6:09device drivers each device that we have
  149. 6:12in our computer
  150. 6:13whether it's a cd or an or a printer or
  151. 6:17something like that or a scanner
  152. 6:18will have a device driver that is
  153. 6:20specific to that device
  154. 6:23then after it has established what
  155. 6:26what it got in the computer the
  156. 6:28operating system will start services
  157. 6:31and there will be a number of services
  158. 6:34that
  159. 6:35will launch upon the start of the
  160. 6:36operating system
  161. 6:38these are these will involve a file
  162. 6:41system
  163. 6:43and then it will build up a network
  164. 6:46stack
  165. 6:46and have the drivers for the keyboard
  166. 6:49and the display and so on
  167. 6:51and the reason for that is that many of
  168. 6:54these are going to be shared between
  169. 6:56different user
  170. 6:57users and users and if you
  171. 7:00were the one that would write an
  172. 7:03application
  173. 7:04that takes the keyboard input and
  174. 7:08does as simple thing as displays
  175. 7:11like a character on the screen would
  176. 7:13have been very cumbersome
  177. 7:15can you imagine that's after writing
  178. 7:17that software i've done that before and
  179. 7:18you know these really bare bones
  180. 7:21computers where you are trying to detect
  181. 7:23the keyboard stroke
  182. 7:24by using very low level program and then
  183. 7:28display some pixels on the screen
  184. 7:32that represent that keystroke that's
  185. 7:35kind of fun
  186. 7:36it's fun maybe to do it once you don't
  187. 7:39want to do it in every single
  188. 7:40application
  189. 7:41the operating system provides means to
  190. 7:44detect that by
  191. 7:46having things like system calls
  192. 7:50so the operating system is going to
  193. 7:52serve that
  194. 7:53for every single one of our applications
  195. 7:56and with many cases comes for free
  196. 8:00you know it is you know it is either
  197. 8:02packaged with the operating system
  198. 8:03um or it is generally packaged for with
  199. 8:06the operating system whether it's
  200. 8:07proprietary
  201. 8:08or open source
  202. 8:11um and then finally when everything is
  203. 8:13set up it
  204. 8:14is there to run and managing managed
  205. 8:17programs
  206. 8:18so there are multiple programs that can
  207. 8:19run at the same time
  208. 8:21whether they are by the same user or
  209. 8:22multiple users i mean this
  210. 8:24um my laptop runs you know
  211. 8:28probably three or four different power
  212. 8:31presentations now it has obs it has a
  213. 8:34web browser open as you have seen
  214. 8:37and and a number of other things that
  215. 8:39are all
  216. 8:40running concurrently
  217. 8:43it also the other important thing about
  218. 8:45the operating system
  219. 8:46it isolates these programs from each
  220. 8:48other none of them
  221. 8:49knows that the other program is running
  222. 8:51it is not bothering them
  223. 8:53whatsoever so they all
  224. 8:56nicely share system resources including
  225. 8:59the peripheral devices
  226. 9:02so that is something that is
  227. 9:05a major function of the operating system
  228. 9:08also if any of these programs
  229. 9:12has any kind of a fault if it crashes
  230. 9:15it is supposed to terminate it
  231. 9:17gracefully
  232. 9:18and not crash everything else
  233. 9:22so the core os has to provide
  234. 9:26some of the basic functions that are
  235. 9:28listed here and there are two
  236. 9:30basic categories it provides the
  237. 9:32isolation between running programs
  238. 9:35so every single program that we have is
  239. 9:37running it
  240. 9:38only in its own world it is unaware of
  241. 9:40everyone of anyone else
  242. 9:42it just uses operating system services
  243. 9:44so it's aware of those
  244. 9:45but if there is another program that is
  245. 9:47using those services
  246. 9:49they don't don't interfere with each
  247. 9:51other
  248. 9:52and then the other thing is it provides
  249. 9:55interaction with the outside world so
  250. 9:57interacts with the devices which is our
  251. 9:59disk
  252. 10:00display network and so on
  253. 10:03in a very convenient way that we can
  254. 10:06just call
  255. 10:07that function okay
  256. 10:11so in order for an operating system to
  257. 10:13run on a particular hardware
  258. 10:15we almost have everything there are a
  259. 10:18few small
  260. 10:19changes to the operating system to the
  261. 10:21to our
  262. 10:22simple data path that need to be added
  263. 10:25but majority of the stuff is already
  264. 10:26there believe it or not so we could
  265. 10:29uh boot and operating system on our
  266. 10:32simple core
  267. 10:33although it wouldn't run that great for
  268. 10:35now a few things
  269. 10:37would make it a lot more pleasant
  270. 10:40to run an operating system so the first
  271. 10:43thing
  272. 10:43is a big one that is following in the
  273. 10:45next set of lectures which is this
  274. 10:46memory
  275. 10:47translation so when we run our
  276. 10:51our venus code or assembly code or c
  277. 10:54code we many of us that are doing class
  278. 10:57projects maybe
  279. 10:58maybe addressing the same memory
  280. 11:00location and that would be a pretty
  281. 11:02major problem if we are really actually
  282. 11:05addressing the same memory location
  283. 11:08you know uh 1 000 hex
  284. 11:11um in in physical dram
  285. 11:14we would be all writing all over each
  286. 11:16other and that would not be good
  287. 11:18so what does the operating system do it
  288. 11:21intercepts that
  289. 11:22uh so-called virtual address and maps it
  290. 11:26into a physical address
  291. 11:27so if there is a hundred of us that are
  292. 11:29going to be writing to the same
  293. 11:31address 1000 we would actually
  294. 11:34think that we are doing that but
  295. 11:35operating system is going to translate
  296. 11:37that to different physical addresses
  297. 11:40depending on how much memory we would
  298. 11:43like
  299. 11:43to to use these things will be moved
  300. 11:46uh you know set uh separated from each
  301. 11:50other
  302. 11:52um so actually so whenever
  303. 11:55we are doing a load or store in our s5
  304. 11:58assembly language
  305. 11:59we issue a virtual address operating
  306. 12:02system translates that virtual address
  307. 12:04into a physical address and there is a
  308. 12:06list of physical addresses that
  309. 12:08correspond
  310. 12:09to our system the other thing
  311. 12:13that is a very important uh so so
  312. 12:16to wrap this up we have to provide means
  313. 12:20of this memory translation
  314. 12:21by our hardware and that's what we are
  315. 12:23going to do the other thing is
  316. 12:24relatively simple here
  317. 12:29it need we need to have support for
  318. 12:31protection and privilege
  319. 12:33so generally we are going to have at
  320. 12:37least
  321. 12:38two running modes uh two different
  322. 12:41levels of protection and privilege
  323. 12:44in in our systems there will be user
  324. 12:47modes
  325. 12:48and supervisor modes risk five also
  326. 12:52supports a third mod uh mode that is
  327. 12:54called the machine mode that is in
  328. 12:56between the user
  329. 12:57and uh supervisor mode so when you look
  330. 12:59at that
  331. 13:00user mode would have the least amount of
  332. 13:02privileges they would come
  333. 13:03the machine mode and supervisor mode is
  334. 13:06the supervisor has the most privileges
  335. 13:11the idea here is that in the user mode
  336. 13:14you
  337. 13:15should not be able to do any damage you
  338. 13:17cannot write over anyone else
  339. 13:19supervisor mode is the one that changes
  340. 13:22memory mappings
  341. 13:23and allocates different memory mappings
  342. 13:26to different users
  343. 13:30so the supervisor can change the mapping
  344. 13:33for
  345. 13:33any given program and it has its own
  346. 13:37mapping from the virtual to physical
  347. 13:41these kind of things the mode change is
  348. 13:43typically
  349. 13:45done by writing into some
  350. 13:48control and status registers you know
  351. 13:50just setting bits and controlling status
  352. 13:51registers
  353. 13:52and all what we need to have are some of
  354. 13:54these designated control and status
  355. 13:56registers and we'll mention
  356. 13:58some of them they're very specific to
  357. 14:00different kinds of of isas
  358. 14:03these control and status registers will
  359. 14:06be there
  360. 14:06such that a user can request something
  361. 14:10from the operating system but cannot
  362. 14:12mess up things
  363. 14:13on the other hand um the supervisor mode
  364. 14:17will have access to more control and
  365. 14:19status registers that we'll be using
  366. 14:21for managing multiple processes um
  367. 14:24competing for different devices
  368. 14:26relatively straightforward you already
  369. 14:28know what they're controlling status
  370. 14:29register we just
  371. 14:30need to know a list of those that are
  372. 14:32needed for running an operating system
  373. 14:35or support running of the operating
  374. 14:36system
  375. 14:38and finally the third important thing
  376. 14:41that we need from the hard
  377. 14:42from the hardware to run an operating
  378. 14:44system is we
  379. 14:46need to be able to handle so-called
  380. 14:48interrupts and
  381. 14:50exceptions and we're going to dive into
  382. 14:52those those are
  383. 14:54essentially
  384. 14:57ways to handle um unusual behavior of a
  385. 15:01program our program
  386. 15:02may be interrupted by an external event
  387. 15:05or may need to handle an internal
  388. 15:08exception
  389. 15:08by you know perhaps detecting an invalid
  390. 15:11instruction
  391. 15:12to do that we have to be able to execute
  392. 15:15something that is called a trap handler
  393. 15:18something
  394. 15:19will be called by the supervisor mode
  395. 15:21that will perform this function for us
  396. 15:23and we can do that on demand it doesn't
  397. 15:25have to happen by
  398. 15:27an external trigger or an internal
  399. 15:29trigger we can just call the supervisor
  400. 15:32to do something for us okay
  401. 15:35that's basically in a nutshell what the
  402. 15:38operating system needs to do
  403. 15:40one more thing that i would like to
  404. 15:42review quickly
  405. 15:43is what happens at boot
  406. 15:48so when the computer turns on
  407. 15:52it really does things in a similar way
  408. 15:56we have done
  409. 15:57in venus we are running a single program
  410. 16:00the first thing that we do we jump to
  411. 16:03one
  412. 16:04predetermined address it really depends
  413. 16:07what it is in this case maybe
  414. 16:092000 is the program counter so the
  415. 16:12program counter is set to a particular
  416. 16:14predetermined value
  417. 16:16and then starts executing some
  418. 16:18instructions
  419. 16:19that are predetermined that are going to
  420. 16:22help us
  421. 16:23boot the operating system
  422. 16:26these instructions are generally stored
  423. 16:29in something that we call flash rom
  424. 16:33rom stands for read-only memory
  425. 16:36but we really don't use these memories
  426. 16:38that are
  427. 16:39just read only for that
  428. 16:43they are reprogrammable so flash
  429. 16:45read-only memories
  430. 16:46as we'll study a bit later are those
  431. 16:50that we read most of the time
  432. 16:5499.99 of a time and then
  433. 16:57rarely we update that sometimes you have
  434. 16:59seen
  435. 17:00that you know your computer would like
  436. 17:02to update
  437. 17:04a boot rom well that's basically what is
  438. 17:07happening
  439. 17:08you get a new flash new new content for
  440. 17:11that
  441. 17:12flash rom and it gets written you've
  442. 17:15seen that it's a fairly
  443. 17:16slow process that's the way how it's
  444. 17:17designed you rarely write to it
  445. 17:19so it's slow but you read it the read
  446. 17:21out of it is really fast
  447. 17:25so let's review what happens
  448. 17:28there in most cases
  449. 17:31here the bios could be
  450. 17:35detected it could be addressed directly
  451. 17:38so you know typically microcontrollers
  452. 17:40will address this so-called bios basic
  453. 17:44input output system that would be living
  454. 17:45on this uh
  455. 17:47flash rom directly but in most cases
  456. 17:51um it will just basically be copied the
  457. 17:53contents of this flash run will be
  458. 17:55copied somewhere into the memory space
  459. 17:57that corresponds to the address where we
  460. 17:59generally start from
  461. 18:01and that is it we start executing
  462. 18:05the content of it whether it's in our
  463. 18:07dram
  464. 18:08or it is sitting in a separate chip it
  465. 18:10just depends
  466. 18:11where are these wires that correspond to
  467. 18:13the address is pointing to
  468. 18:16so at boot there are several steps
  469. 18:20that are followed so this basic input
  470. 18:24output system
  471. 18:25which stands for bias finds
  472. 18:29a storage device it generally has a few
  473. 18:32options to to look for and if you had an
  474. 18:36older computer it may try to boot
  475. 18:38from a disk
  476. 18:41one disc two or a compact disc
  477. 18:44or there used to be these things that we
  478. 18:46they're pretty hard to find these days
  479. 18:48like
  480. 18:48floppy disks or it might boot from a usb
  481. 18:51drive
  482. 18:52and basically is looking where to find
  483. 18:55the first
  484. 18:56sector of data the first block of data
  485. 18:59and that first block of data contains
  486. 19:01some really important information that
  487. 19:04information is something that is called
  488. 19:05the bootloader
  489. 19:06that's the first step of loading
  490. 19:10the operating system bootloader may be
  491. 19:13able to support multiple operating
  492. 19:14systems that's how we have dual boots or
  493. 19:16we can boot
  494. 19:17different versions of of our
  495. 19:21operating system many people find it
  496. 19:23convenient
  497. 19:25so in that step of the bootloader will
  498. 19:28load the kernel of the operating system
  499. 19:30the basic key functions of the operating
  500. 19:32system
  501. 19:34into a memory location and jump into it
  502. 19:36from there
  503. 19:37the os will boot which means it will
  504. 19:40initialize services it will initialize
  505. 19:43file
  506. 19:43file system uh get the device drivers
  507. 19:46going and you're going to see if you're
  508. 19:47doing that in linux you'll
  509. 19:48see this scrolling text in front of you
  510. 19:51that will
  511. 19:52mostly be telling you that things are
  512. 19:54okay
  513. 19:55if something is not quite right and you
  514. 19:59in some cases you need to worry about
  515. 20:01but most of the time you're going to see
  516. 20:03get a bunch of a case there and then
  517. 20:06when it is done booting
  518. 20:08it just goes into an infinite loop um in
  519. 20:11most cases it will just
  520. 20:13go into the loop that waits for an input
  521. 20:17and that input may just give you a
  522. 20:19prompt here
  523. 20:20and in that prompt it will wait for the
  524. 20:22keyboard board
  525. 20:24input where you can type something
  526. 20:27and launch a new application
  527. 20:30and that is it we are going to look
  528. 20:34into some of the other functions of the
  529. 20:36operating system and how do they tie
  530. 20:39to the hardware in the module
  531. 20:42after this break see you then

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 28.2 - OS & Virtual Memory Intro: Operating System Basics by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,951 words across 531 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.