[CS61C FA20] Lecture 28.2 - OS & Virtual Memory Intro: Operating System Basics — Transcript
Full transcript
- 0:00[Music]
- 0:10hello
- 0:11and welcome back to our discussion about
- 0:14operating systems as an introduction
- 0:17to dealing with the virtual memory
- 0:20so what we did so far we introduced the
- 0:23operating system
- 0:24as a big differentiator in our computing
- 0:28systems
- 0:29that is something that makes it possible
- 0:33to run instead of just one application
- 0:35at a time to run
- 0:36many of them and also to make many
- 0:39things
- 0:40around running that application a lot
- 0:43easier
- 0:46so let's dive a bit into
- 0:49what does the operating system do and
- 0:52how does it help us
- 0:55but also we're going to try to use it to
- 0:58justify the re the the needs for this
- 1:01concept of virtual memory
- 1:04okay so the first thing that we're going
- 1:06to take a look at
- 1:07is this just software component
- 1:11of the operating system it is softer but
- 1:14it is commonly
- 1:15a very large chunk of software often the
- 1:18most complex program that we have on our
- 1:21computers is the operating system so
- 1:24if we look at this
- 1:28there is this web website that kind of
- 1:31tries to compare
- 1:32how much of a code do we have in
- 1:34different kinds
- 1:36of applications or different kinds of
- 1:38systems so this starts
- 1:40yeah i think this was a snapshot around
- 1:422015-16 or so
- 1:45that is comparing the code base for
- 1:47different kinds of things
- 1:49so it starts with a simple iphone
- 1:52game app that you know can get by with
- 1:55like 10 000 lines of code
- 1:57perhaps a little bit more than a class
- 2:00project
- 2:00uh that you have seen then the early
- 2:04unix from the 70s also had about 10 000
- 2:07lines of code
- 2:08viruses around that size as well
- 2:13then as we go down through this you know
- 2:17space shuttle had 0.4 million lines of
- 2:21code
- 2:22um a lot more but not that that much
- 2:24more you have to be written in a very
- 2:26very compact way then you go down to
- 2:30other systems
- 2:32uh you know a million lines of code gets
- 2:34you
- 2:35quite a few interesting things for
- 2:37example in in order to encode to
- 2:38replicate the bacteria
- 2:40the amount of dna that it stores holds
- 2:44something that is an equivalent to 1.1
- 2:47um
- 2:48millions many million lines of code um
- 2:51f22 fighter jet 1.7 million lines of
- 2:54code
- 2:55uh linux kernel all linux kernel 2.2
- 2:58um is of the order of two million lines
- 3:02of code
- 3:03jurassic park was around that size
- 3:08that size as well as you go browse
- 3:10through this you will find some other
- 3:12interesting things
- 3:13uh f35 fighter jet had 24 million lines
- 3:16of code microsoft office
- 3:18back in 2001 had 25 million lines of
- 3:20code
- 3:22and that the other operating systems
- 3:25that we have here like windows xp
- 3:30had close to 15 million lines of code
- 3:33and so
- 3:33did microsoft office 2003.
- 3:37um going down we see
- 3:40more complex things nowadays you will
- 3:44find
- 3:45os down here mac likes
- 3:48older version 2016-ish version of mac os
- 3:52had over 80 million lines of code
- 3:55modern car software like a tesla even
- 3:58back then had 100 million lines of code
- 4:00in order to encode mars's genome that
- 4:03was equivalent to more than 100 million
- 4:06lines of code on the bottom the entire
- 4:08google's code
- 4:10base was 2 billion lines of code
- 4:14so while operating system while
- 4:16operating system is not
- 4:17as big as google's code base it is up
- 4:19there among
- 4:20the most complex things that we have
- 4:23built
- 4:26so back to to this
- 4:29um you know here this is a plot over
- 4:32many many years
- 4:33how did the code base for the linux grow
- 4:37um so the current uh versions in this
- 4:39plots
- 4:41this website plots it up to roughly
- 4:4420
- 4:4819 or so puts
- 4:51linux at about 20
- 4:55millions lines of code
- 4:58so what does what do these 20 millions
- 5:01of lines of code do
- 5:04a lot of useful things so os
- 5:08is almost the first thing that runs when
- 5:10the computer starts
- 5:12i'm going to go in a little bit more of
- 5:13a detail with that in
- 5:15just a second uh first thing is going to
- 5:18be something that
- 5:19is you know will be loaded is the bios
- 5:21and the bootloader but then after that
- 5:24we don't jump into applications we load
- 5:26the operating system
- 5:28then in next thing
- 5:31that it will do as soon as it finds
- 5:33itself comfortable
- 5:34inside your computer operating system is
- 5:36going to find all the devices they'll
- 5:38find out how many cores are there
- 5:40what kind of io devices do you have do
- 5:43you have a printer
- 5:44a display keyboard what kind of disks
- 5:47and so on
- 5:48and it is going to do something in linux
- 5:51world
- 5:52it will call it will build a device 3.
- 5:55and by using that we'll know what kind
- 5:58of resources we have
- 5:59and what kind of operating system
- 6:01functions we can use
- 6:02to access those devices that is often
- 6:05relied
- 6:06on to by by using hardware specific
- 6:09device drivers each device that we have
- 6:12in our computer
- 6:13whether it's a cd or an or a printer or
- 6:17something like that or a scanner
- 6:18will have a device driver that is
- 6:20specific to that device
- 6:23then after it has established what
- 6:26what it got in the computer the
- 6:28operating system will start services
- 6:31and there will be a number of services
- 6:34that
- 6:35will launch upon the start of the
- 6:36operating system
- 6:38these are these will involve a file
- 6:41system
- 6:43and then it will build up a network
- 6:46stack
- 6:46and have the drivers for the keyboard
- 6:49and the display and so on
- 6:51and the reason for that is that many of
- 6:54these are going to be shared between
- 6:56different user
- 6:57users and users and if you
- 7:00were the one that would write an
- 7:03application
- 7:04that takes the keyboard input and
- 7:08does as simple thing as displays
- 7:11like a character on the screen would
- 7:13have been very cumbersome
- 7:15can you imagine that's after writing
- 7:17that software i've done that before and
- 7:18you know these really bare bones
- 7:21computers where you are trying to detect
- 7:23the keyboard stroke
- 7:24by using very low level program and then
- 7:28display some pixels on the screen
- 7:32that represent that keystroke that's
- 7:35kind of fun
- 7:36it's fun maybe to do it once you don't
- 7:39want to do it in every single
- 7:40application
- 7:41the operating system provides means to
- 7:44detect that by
- 7:46having things like system calls
- 7:50so the operating system is going to
- 7:52serve that
- 7:53for every single one of our applications
- 7:56and with many cases comes for free
- 8:00you know it is you know it is either
- 8:02packaged with the operating system
- 8:03um or it is generally packaged for with
- 8:06the operating system whether it's
- 8:07proprietary
- 8:08or open source
- 8:11um and then finally when everything is
- 8:13set up it
- 8:14is there to run and managing managed
- 8:17programs
- 8:18so there are multiple programs that can
- 8:19run at the same time
- 8:21whether they are by the same user or
- 8:22multiple users i mean this
- 8:24um my laptop runs you know
- 8:28probably three or four different power
- 8:31presentations now it has obs it has a
- 8:34web browser open as you have seen
- 8:37and and a number of other things that
- 8:39are all
- 8:40running concurrently
- 8:43it also the other important thing about
- 8:45the operating system
- 8:46it isolates these programs from each
- 8:48other none of them
- 8:49knows that the other program is running
- 8:51it is not bothering them
- 8:53whatsoever so they all
- 8:56nicely share system resources including
- 8:59the peripheral devices
- 9:02so that is something that is
- 9:05a major function of the operating system
- 9:08also if any of these programs
- 9:12has any kind of a fault if it crashes
- 9:15it is supposed to terminate it
- 9:17gracefully
- 9:18and not crash everything else
- 9:22so the core os has to provide
- 9:26some of the basic functions that are
- 9:28listed here and there are two
- 9:30basic categories it provides the
- 9:32isolation between running programs
- 9:35so every single program that we have is
- 9:37running it
- 9:38only in its own world it is unaware of
- 9:40everyone of anyone else
- 9:42it just uses operating system services
- 9:44so it's aware of those
- 9:45but if there is another program that is
- 9:47using those services
- 9:49they don't don't interfere with each
- 9:51other
- 9:52and then the other thing is it provides
- 9:55interaction with the outside world so
- 9:57interacts with the devices which is our
- 9:59disk
- 10:00display network and so on
- 10:03in a very convenient way that we can
- 10:06just call
- 10:07that function okay
- 10:11so in order for an operating system to
- 10:13run on a particular hardware
- 10:15we almost have everything there are a
- 10:18few small
- 10:19changes to the operating system to the
- 10:21to our
- 10:22simple data path that need to be added
- 10:25but majority of the stuff is already
- 10:26there believe it or not so we could
- 10:29uh boot and operating system on our
- 10:32simple core
- 10:33although it wouldn't run that great for
- 10:35now a few things
- 10:37would make it a lot more pleasant
- 10:40to run an operating system so the first
- 10:43thing
- 10:43is a big one that is following in the
- 10:45next set of lectures which is this
- 10:46memory
- 10:47translation so when we run our
- 10:51our venus code or assembly code or c
- 10:54code we many of us that are doing class
- 10:57projects maybe
- 10:58maybe addressing the same memory
- 11:00location and that would be a pretty
- 11:02major problem if we are really actually
- 11:05addressing the same memory location
- 11:08you know uh 1 000 hex
- 11:11um in in physical dram
- 11:14we would be all writing all over each
- 11:16other and that would not be good
- 11:18so what does the operating system do it
- 11:21intercepts that
- 11:22uh so-called virtual address and maps it
- 11:26into a physical address
- 11:27so if there is a hundred of us that are
- 11:29going to be writing to the same
- 11:31address 1000 we would actually
- 11:34think that we are doing that but
- 11:35operating system is going to translate
- 11:37that to different physical addresses
- 11:40depending on how much memory we would
- 11:43like
- 11:43to to use these things will be moved
- 11:46uh you know set uh separated from each
- 11:50other
- 11:52um so actually so whenever
- 11:55we are doing a load or store in our s5
- 11:58assembly language
- 11:59we issue a virtual address operating
- 12:02system translates that virtual address
- 12:04into a physical address and there is a
- 12:06list of physical addresses that
- 12:08correspond
- 12:09to our system the other thing
- 12:13that is a very important uh so so
- 12:16to wrap this up we have to provide means
- 12:20of this memory translation
- 12:21by our hardware and that's what we are
- 12:23going to do the other thing is
- 12:24relatively simple here
- 12:29it need we need to have support for
- 12:31protection and privilege
- 12:33so generally we are going to have at
- 12:37least
- 12:38two running modes uh two different
- 12:41levels of protection and privilege
- 12:44in in our systems there will be user
- 12:47modes
- 12:48and supervisor modes risk five also
- 12:52supports a third mod uh mode that is
- 12:54called the machine mode that is in
- 12:56between the user
- 12:57and uh supervisor mode so when you look
- 12:59at that
- 13:00user mode would have the least amount of
- 13:02privileges they would come
- 13:03the machine mode and supervisor mode is
- 13:06the supervisor has the most privileges
- 13:11the idea here is that in the user mode
- 13:14you
- 13:15should not be able to do any damage you
- 13:17cannot write over anyone else
- 13:19supervisor mode is the one that changes
- 13:22memory mappings
- 13:23and allocates different memory mappings
- 13:26to different users
- 13:30so the supervisor can change the mapping
- 13:33for
- 13:33any given program and it has its own
- 13:37mapping from the virtual to physical
- 13:41these kind of things the mode change is
- 13:43typically
- 13:45done by writing into some
- 13:48control and status registers you know
- 13:50just setting bits and controlling status
- 13:51registers
- 13:52and all what we need to have are some of
- 13:54these designated control and status
- 13:56registers and we'll mention
- 13:58some of them they're very specific to
- 14:00different kinds of of isas
- 14:03these control and status registers will
- 14:06be there
- 14:06such that a user can request something
- 14:10from the operating system but cannot
- 14:12mess up things
- 14:13on the other hand um the supervisor mode
- 14:17will have access to more control and
- 14:19status registers that we'll be using
- 14:21for managing multiple processes um
- 14:24competing for different devices
- 14:26relatively straightforward you already
- 14:28know what they're controlling status
- 14:29register we just
- 14:30need to know a list of those that are
- 14:32needed for running an operating system
- 14:35or support running of the operating
- 14:36system
- 14:38and finally the third important thing
- 14:41that we need from the hard
- 14:42from the hardware to run an operating
- 14:44system is we
- 14:46need to be able to handle so-called
- 14:48interrupts and
- 14:50exceptions and we're going to dive into
- 14:52those those are
- 14:54essentially
- 14:57ways to handle um unusual behavior of a
- 15:01program our program
- 15:02may be interrupted by an external event
- 15:05or may need to handle an internal
- 15:08exception
- 15:08by you know perhaps detecting an invalid
- 15:11instruction
- 15:12to do that we have to be able to execute
- 15:15something that is called a trap handler
- 15:18something
- 15:19will be called by the supervisor mode
- 15:21that will perform this function for us
- 15:23and we can do that on demand it doesn't
- 15:25have to happen by
- 15:27an external trigger or an internal
- 15:29trigger we can just call the supervisor
- 15:32to do something for us okay
- 15:35that's basically in a nutshell what the
- 15:38operating system needs to do
- 15:40one more thing that i would like to
- 15:42review quickly
- 15:43is what happens at boot
- 15:48so when the computer turns on
- 15:52it really does things in a similar way
- 15:56we have done
- 15:57in venus we are running a single program
- 16:00the first thing that we do we jump to
- 16:03one
- 16:04predetermined address it really depends
- 16:07what it is in this case maybe
- 16:092000 is the program counter so the
- 16:12program counter is set to a particular
- 16:14predetermined value
- 16:16and then starts executing some
- 16:18instructions
- 16:19that are predetermined that are going to
- 16:22help us
- 16:23boot the operating system
- 16:26these instructions are generally stored
- 16:29in something that we call flash rom
- 16:33rom stands for read-only memory
- 16:36but we really don't use these memories
- 16:38that are
- 16:39just read only for that
- 16:43they are reprogrammable so flash
- 16:45read-only memories
- 16:46as we'll study a bit later are those
- 16:50that we read most of the time
- 16:5499.99 of a time and then
- 16:57rarely we update that sometimes you have
- 16:59seen
- 17:00that you know your computer would like
- 17:02to update
- 17:04a boot rom well that's basically what is
- 17:07happening
- 17:08you get a new flash new new content for
- 17:11that
- 17:12flash rom and it gets written you've
- 17:15seen that it's a fairly
- 17:16slow process that's the way how it's
- 17:17designed you rarely write to it
- 17:19so it's slow but you read it the read
- 17:21out of it is really fast
- 17:25so let's review what happens
- 17:28there in most cases
- 17:31here the bios could be
- 17:35detected it could be addressed directly
- 17:38so you know typically microcontrollers
- 17:40will address this so-called bios basic
- 17:44input output system that would be living
- 17:45on this uh
- 17:47flash rom directly but in most cases
- 17:51um it will just basically be copied the
- 17:53contents of this flash run will be
- 17:55copied somewhere into the memory space
- 17:57that corresponds to the address where we
- 17:59generally start from
- 18:01and that is it we start executing
- 18:05the content of it whether it's in our
- 18:07dram
- 18:08or it is sitting in a separate chip it
- 18:10just depends
- 18:11where are these wires that correspond to
- 18:13the address is pointing to
- 18:16so at boot there are several steps
- 18:20that are followed so this basic input
- 18:24output system
- 18:25which stands for bias finds
- 18:29a storage device it generally has a few
- 18:32options to to look for and if you had an
- 18:36older computer it may try to boot
- 18:38from a disk
- 18:41one disc two or a compact disc
- 18:44or there used to be these things that we
- 18:46they're pretty hard to find these days
- 18:48like
- 18:48floppy disks or it might boot from a usb
- 18:51drive
- 18:52and basically is looking where to find
- 18:55the first
- 18:56sector of data the first block of data
- 18:59and that first block of data contains
- 19:01some really important information that
- 19:04information is something that is called
- 19:05the bootloader
- 19:06that's the first step of loading
- 19:10the operating system bootloader may be
- 19:13able to support multiple operating
- 19:14systems that's how we have dual boots or
- 19:16we can boot
- 19:17different versions of of our
- 19:21operating system many people find it
- 19:23convenient
- 19:25so in that step of the bootloader will
- 19:28load the kernel of the operating system
- 19:30the basic key functions of the operating
- 19:32system
- 19:34into a memory location and jump into it
- 19:36from there
- 19:37the os will boot which means it will
- 19:40initialize services it will initialize
- 19:43file
- 19:43file system uh get the device drivers
- 19:46going and you're going to see if you're
- 19:47doing that in linux you'll
- 19:48see this scrolling text in front of you
- 19:51that will
- 19:52mostly be telling you that things are
- 19:54okay
- 19:55if something is not quite right and you
- 19:59in some cases you need to worry about
- 20:01but most of the time you're going to see
- 20:03get a bunch of a case there and then
- 20:06when it is done booting
- 20:08it just goes into an infinite loop um in
- 20:11most cases it will just
- 20:13go into the loop that waits for an input
- 20:17and that input may just give you a
- 20:19prompt here
- 20:20and in that prompt it will wait for the
- 20:22keyboard board
- 20:24input where you can type something
- 20:27and launch a new application
- 20:30and that is it we are going to look
- 20:34into some of the other functions of the
- 20:36operating system and how do they tie
- 20:39to the hardware in the module
- 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.