Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
[MUSIC PLAYING] PROFESSOR: Hello and welcome back to our discussion about operating systems as an introduction to dealing with the virtual memory.
So what we did so far, we introduced the operating system as a big differentiator in our computing systems.
That is something that makes it possible to run instead of just one application at a time, to run many of them. And also to make many things around running that application a lot easier.
So let's dive a bit into what does the operating system do and how does it help us, but also we are going to try to use it to justify the means for this concept of virtual memory.
Okay, so the first thing that we're going to take a look at is this just software component of the operating system. It is software, but it is commonly a very large chunk of software.
Often, the most complex program that we have on our computers is the operating system.
So if we look at this and this website that tries to compare how much of our code do we have in different kinds of applications, so different kinds of systems.
So this starts — I think this was a snapshot around 2015-16 or so that is comparing the code base for different kinds of things.
So it starts with a simple iPhone game app that can get by with 10,000 lines of code. Perhaps a little bit more than a class project that you have seen.
Then the early Unix from the '70s also had about 10,000 lines of code, viruses around that size as well.
Then as we go down through this, space shuttle had 0.4 million lines of code.
A lot more, but not that much more had to be written in a very, very compact way. Then you go down to other systems.
A million lines of code gets you quite a few interesting things.
For example, in order to encode to replicate the bacteria, the amount of DNA that it stores holds something that is an equivalent to 1.1 million lines of code.
F-22 fighter jet, 1.7 million lines of code. Linux Kernel or Linux Kernel 2.2 is of the order of 2 million lines of code.
Jurassic park was around that size as well. And as you go browse through this, you'll find some other interesting things. F-35 fighter jet had 24 million lines of code.
Microsoft Office back in 2001 had 25 million lines of code, and the other operating systems that we have here like Windows XP had close to 15 million lines of code and so that Microsoft Office, 2003.
Going down, we see more complex things nowadays. You will find Mac OS down here.
Mac OS older version, 2016 version of Mac OS had over 80 million lines of code.
Modern software, like a Tesla, even back then had 100 million lines of code in order to encode monster's genome that was equivalent to more than 100 million lines of code.
On the bottom, the entire Google's code base was $2 billion lines of code.
So while operating system is not as big as Google's code base, it is up there among the most complex things that we have built. So back to this.
This is a plot over many, many years how did the code base for the Linux grow?
So the current versions in this plot — this website plots it up to roughly 2019 or so puts Linux at about 20-ish million lines of code.
So what do these 20 millions of lines of code do? A lot of useful things. So OS is almost the first thing that runs when the computer starts.
I'm going to go in a little bit more of a detail with that in just a second.
First thing is going to be something that will be loaded is the bios and the bootloader, but then after that, we don't jump into applications, we load the operating system.
Then next thing that it will do as soon as it finds itself comfortable inside your computer, operating system is going to find all the devices.
They'll find out how many cores are there, what kind of IO devices do you have? Do you have a printer or a display, keyboard?
What kind of disks, and so on, and it is going to do something. And Linux, it'll build a device 3.
And by using that, we'll know what kind of resources we have and what kind of operating system functions we can use to access those devices.
That is often relied on to by using hardware-specific device drivers.
Each device that we have in our computer, whether it's a CD or a printer or something like that or a scanner will have a device driver that is specific to that device.
Then after it has established what it got in the computer, the operating system will start services.
And there'll be a number of services that will launch upon the start of the operating system.
These will involve a file system, and then it will build up a network stack and have the drivers for the keyboard and the display and so on.
And the reason for that is that many of these are going to be shared between different users and uses, and if you were the one that would write an application that takes the keyboard input and does as simple thing as displays a character on the screen,
would have been very cumbersome. Can you imagine that software, writing that software?
I've done that before on these really bare bones computers, where you are trying to detect the keyboard stroke by using very low level program, and then display some pixels on the screen that represent that keystroke.
That's kind of fun. It's fun maybe to do it once. You don't want to do it in every single application.
The operating system provides means to detect that by having things like system calls.
So the operating system is going to serve that for every single one of our applications, and in many cases, comes for free.
It is either packaged with the operating system or it is generally packaged with the operating system, whether it's proprietary or open source.
And then finally, when everything is set up, it is there to run and manage programs.
So there are multiple programs that can run at the same time, whether they are by the same user or multiple users. I mean, my laptop runs probably three or four different PowerPoint presentations now.
It has OBS, it has a web browser open as you have seen, and a number of other things that are all running concurrently.
The other important thing about the operating system, it isolates these programs from each other. None of them knows that the other program is running.
It is not bothering them whatsoever, so they all nicely share system resources, including the peripheral devices.
So that is something that is a major function of the operating system.
Also, if any of these programs has any kind of a fault, if it crashes, it is supposed to be terminated gracefully and not crash everything else.
So the core OS has to provide some of the basic functions that are listed here, and there are two basic categories. It provides the isolation between running programs.
So every single program that we have is running it only in its own world. It is unaware of everyone of anyone else. It just uses operating system services, so it's aware of those.
But if there is another program that is using those services, they don't interfere with each other, and then the other thing is it provides interaction with the outside world.
So it interacts with the devices, which is our desk display network and so on in a very convenient way that we can just call that function.
So in order for an operating system to run on a particular hardware, we almost have everything.
There are few small changes to the operating system — to our simple data path that need to be added, but majority of the stuff is already there, believe it or not.
So we could put an operating system on our simple core, although it wouldn't run that great for now. A few things would make it a lot more pleasant to run an operating system.
So the first thing is a big one that is following in the next set of lectures, which is this memory translation.
So when we run our venous code or assembly code or C code, many of us that are doing class projects maybe addressing the same memory location.
And that would be a pretty major problem if we had really actually addressing the same memory location 1,000 hits in physical DRAM.
We would be all writing all over each other, and that would not be good. So what is the operating system do? It intercepts that so-called virtual address and maps it into a physical address.
So if there is hundreds of us that are going to be writing to the same address 1,000, we would actually think that we are doing that, but our operating system is going to translate that to different physical addresses, depending on how much memory we would like to use, these things will be moved.
Separated from each other. So actually, so whenever we are doing a load or store in our last five assembly language, we issue a virtual address.
Operating system translates that virtual address into a physical address, and there is a list of physical addresses that correspond to our system.
The other thing that is a very important — so to wrap this up, we have to provide means of this memory translation by our hardware, and that's what we are going to do.
The other thing is relatively simple here.
We need to have some porphyritic protection and privilege.
So generally, we are going to have at least two running modes to different levels of protection and privilege in our systems.
There will be user modes and supervisor modes. RISC-V also supports a third mode that is called the machine mode that is in between the user and supervisor mode.
So when you look at that, user mode will have the least amount of privileges then would come the machine mode and supervisor mode is the supervisor has the most privileges.
The idea here is that, in the user mode, you should not be able to do any damage. You cannot write over anyone else.
Supervisor mode is the one that changes memory mappings and allocates different memory mappings to different users.
So a supervisor can change the mapping for any given program and it has its own mapping from the virtual to physical.
These kind of things, the mode change is typically done by writing into some control and status registers.
Just setting bits and controlling status registers, and all what we need to have are some of these designated control and status registers, and I'll mention some of them, they're very specific to different kinds of ISAs.
These control and status registers will be there such that a user can request something from the operating system but cannot mess up things.
On the other hand, the supervisor mode will have access to more control and status registers it will be using for managing multiple processes competing for different devices.
Relatively straightforward. You already know what their controlling status register is. We just need to a list of those that are needed for running an operating system or support running of the operating system.
And finally, the third important thing that we need from the hardware to run an operating system is we need to be able to handle so-called interrupts and exceptions, and we're going to dive into those.
Those are essentially ways to handle unusual behavior of a program.
Our program may be interrupted by an internal external event or may need to handle an internal exception by perhaps detecting an invalid instruction.
To do that, we have to be able to execute something that is called a trap handler.
Something will be called by the supervisor mode that will perform this function for us, and we can do that on demand.
It doesn't have to happen by an external trigger or an internal trigger, we can just call the supervisor to do something for us.
Okay, that's basically — in a nutshell — what the operating system needs to do. One more thing that they would like to review quickly is what happens at boot.
So when the computer turns on, it really does things in a similar way we have done in Venus. We are running a single program.
The first thing that we do, we jump to one pre-determined address. It really depends what it is in this case. Maybe 2,000 is the program counter.
The program counter is set to a particular predetermined value, and then starts executing some instructions that are predetermined that are going to help us boot the operating system.
These instructions are generally stored in something that we call flash ROM.
ROM stands for read only memory, but we really don't use these memories that are just read only. For that, they are reprogrammable.
So flash read only memories, as we'll study a bit later, are those that we read most of the time. 99.99% of a time, and then rarely we update that.
Sometimes, you have seen that your computer would like to update a boot ROM. Well, that's basically what is happening.
You get a new flash — new content for that flash ROM, and it gets written. You've seen that it's a fairly slow process. That's the way how it's designed.
You rarely write it, so it's slow, but the readout of it is really fast. So let's review what happens there.
In most cases here, the bias could be detected — it could be addressed directly.
So typically, microcontrollers will address this so-called bias, basic input output system, that would be living on this Flash ROM directly.
But in most cases, it will just basically be copied. The contents of this flash and will be copied somewhere into the memory space that corresponds to the address where we generally start from.
And that is it. We start executing the content of it, whether it's in our DRAM or it is sitting in a separate chip.
It just depends where are these wires that correspond to the address is pointing to. So at boot, there are several steps that are followed.
So this basic input output system, which stands for bias, finds a storage device.
It generally has a few options to look for, and if you had an older computer, it may try to boot from a disk 1, disk 2, or a compact disk, or there used to be these things that we — and they're pretty hard to find these days like floppy disks, or it might boot from a USB drive.
And basically, it's looking where to find the first sector of data, the first block of data. And that first block of data contains some really important information.
That information is something that is called the bootloader. That's the first step of loading the operating system. Bootloader may be able to support multiple operating systems.
That's how we have dual boot so we can boot different versions of our operating system. Many people find it convenient.
So in that step of a bootloader, we'll load the kernel of the operating system. The basic key functions of the operating system into a memory location and jump into it.
From there, the OS will boot, which means it will initialize services, it will initially analyze file system, get the device drivers going, and you're going to see if you're doing that, in Linux, you'll see this scrolling text in front of you that will mostly be telling you that things are OK.
If something is not quite right, and in some cases, you need to worry about. But most of the time, you're going to see — get a bunch of okays there.
And then when it is done booting, it just goes into an infinite loop.
In most cases, it will just go into the loop that waits for an input, and that input may just give you a prompt here, and in that prompt, it will wait for the keyboard input, where you can type something and launch a new application.
And that is it. We are going to look into some of the other functions of the operating system and how do they tie to the hardware in the module after this break.
See you then.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.