WEBVTT 1 00:00:01.380 --> 00:00:10.830 William Cheng: This is the second part of lecture 19 so we just finish the device stuff. Now we're going to the last part of Section chapter four. 2 00:00:11.250 --> 00:00:24.660 William Cheng: And the title is called rethinking the operating system. So, you know, even in the middle of the textbook. They started rethinking about the operating system. So what is wrong with the operating system that we have helped go so far. 3 00:00:25.650 --> 00:00:35.850 William Cheng: So and also what is the solution for it so far the operating system that we have looked at is a monolithic operating system. So again, the sort of definition of monolithic operating system is that 4 00:00:36.810 --> 00:00:41.400 William Cheng: When you finish compiling the operating system, the operating system is sitting on this as one giant file. 5 00:00:41.760 --> 00:00:49.350 William Cheng: And then at the time when you load the operating system we unfold the operating system into memory and we jump into it. And at that time, the entire operating system is it 6 00:00:49.800 --> 00:00:59.070 William Cheng: Is a memory. Okay, so the main advantage of this approach is that the performance of the operating systems can be very good. So because the entire operating system be just one executable. 7 00:00:59.460 --> 00:01:04.110 William Cheng: It's almost like are basically like our weeks kernel or we need this is a monolithic companies to Sam. 8 00:01:04.620 --> 00:01:10.890 William Cheng: If any part of your kernel wants to use any kind of a global variable kind of a global data structure if you know the structure of 9 00:01:11.550 --> 00:01:17.400 William Cheng: The sort of the colonel data structure. You can use them directly. Okay, so in this case the performance is going to be really good. 10 00:01:18.120 --> 00:01:25.380 William Cheng: But what is the downside of the Mosaic operating system over here, as it turns out that its reliability is that you going to end up with a buggy, Colonel. 11 00:01:26.160 --> 00:01:29.010 William Cheng: That so because any part of your operating system dies. 12 00:01:29.580 --> 00:01:36.780 William Cheng: It's going to bring out the entire kernel and in the in the first part of this lecture, I just mentioned in 1990s, Microsoft, get a really bad. 13 00:01:37.110 --> 00:01:42.930 William Cheng: Reputation and because of Colonel keep crashing. As it turns out, most of the time it crashes, because of the device driver that 14 00:01:43.470 --> 00:01:47.640 William Cheng: Because of the device device driver bugs and that will bring down the entire operating system. 15 00:01:48.120 --> 00:01:55.470 William Cheng: And then so therefore it will be nice if the device driver can be isolated from the rest of the operating system. In this case, when a device driver dies. 16 00:01:55.860 --> 00:01:57.720 William Cheng: They will not affect the rest of the operating system. 17 00:01:58.200 --> 00:02:05.880 William Cheng: Okay, so, so the solution over here is to shrink the code inside of privilege mo. So instead of privilege mo want the code to be a smallest possible 18 00:02:06.030 --> 00:02:12.000 William Cheng: Everything else we're going to send them into user space. So for example, the device driver is a really good thing to send into the user space. 19 00:02:12.360 --> 00:02:16.320 William Cheng: Okay. In the end, turns out to be very difficult to implement because it because it will be too slow. 20 00:02:16.800 --> 00:02:24.060 William Cheng: So, India, we still put the device drivers are operating system kernel. But, you know, again, it's sort of a good thing to think about how to actually get this stuff. 21 00:02:24.480 --> 00:02:31.560 William Cheng: Okay, so, so, so at the end of chapter four. We're going to talk about two different approaches to shrink the size of the Colonel. 22 00:02:32.070 --> 00:02:35.460 William Cheng: So again, the colonel is partly obviously them that has the 23 00:02:35.940 --> 00:02:44.280 William Cheng: Execute inside of privilege Mo, right. So we want to make that code as small as possible, right. So this way, your current, it will be very reliable and you're not gonna have any bugs. 24 00:02:45.000 --> 00:02:51.930 William Cheng: That are the two approaches going to spend most of our time talking about virtual machines. One of the reasons that because because we use that a lot. 25 00:02:52.320 --> 00:02:59.400 William Cheng: It's very popular this day. The second way is actually not very popular. It's called micro kernels. So micro kernels to make the Colonel, really, really small. 26 00:02:59.910 --> 00:03:06.240 William Cheng: So we're gonna sort of briefly talk about, you know what, what kind of stuff as people try yeah well as the first one talk about virtual machine. 27 00:03:07.050 --> 00:03:11.880 William Cheng: So the basic idea here is that, you know, you will will will 28 00:03:12.480 --> 00:03:21.930 William Cheng: Will be talking about it. Most often, the system provide isolation between application will also we can also isolate the operating system from the, from the user application, right. 29 00:03:22.200 --> 00:03:27.120 William Cheng: This way the user application cannot hurt the ordinances them and also the user application cannot hurt each other. 30 00:03:27.540 --> 00:03:39.570 William Cheng: Okay, the question is, can we do the same thing for the operating system, can we take the obviously then we will divide them into parts so that when each part of them when it dies, it doesn't affect the rest of the system. Right. It will be great if we can do that. Yeah. 31 00:03:41.640 --> 00:03:52.860 William Cheng: I mean, of course, the, the answer is always a yeah there's a way to do it, but at what cost if the cost is too you know too expensive in terms of performance improvement in terms of memory or something like that, maybe, in that case is not doable. 32 00:03:53.250 --> 00:03:59.430 William Cheng: Okay, so therefore we're going to sort of see what is the trade off between implementing you know the the to to to 33 00:03:59.970 --> 00:04:08.190 William Cheng: To implement this kind of isolation versus what what is the cost going to be yeah I mean of course one simple solutions to say everything everything they user space. 34 00:04:08.700 --> 00:04:14.160 William Cheng: So in that case, when something crashing the user space is not going to affect the rest of the operating system. So again, that's sort of the basic idea. 35 00:04:15.180 --> 00:04:28.020 William Cheng: Alright. So as it turns out, virtual machine is a router. The old technology. It was invented by IBM more than 50 years ago they had a different motivation to want to build virtual machines there. So let's first talk about IBM virtual machine. 36 00:04:29.100 --> 00:04:30.480 William Cheng: So IBM has, you know, 37 00:04:31.530 --> 00:04:41.340 William Cheng: Has a system called CMS. Now it's a single user time sharing machines again time sharing is a really, really old IBM term. What it means is that there's an interactive user 38 00:04:42.000 --> 00:04:47.040 William Cheng: Okay, so if you think about the IBM mainframe. They're really, really big computer they sort of fill up the entire room. 39 00:04:47.220 --> 00:04:55.710 William Cheng: It's one giant computer and it's a single user system. Okay, so there's only one user sits in front of that. And that's the only system that they had my single user using up 40 00:04:56.040 --> 00:05:10.800 William Cheng: An entire room local computer. Sounds like a total waste. Right. But it was very popular because people like to be able to interact with the computer right before the, you know, before the CMS people have to sort of submit jobs to the mainframe. And then when the mainframe is done. 41 00:05:12.240 --> 00:05:18.720 William Cheng: You go to the printer and then you see the printout, and that's going to be the sort of the result of your, you know, of your program. 42 00:05:19.290 --> 00:05:30.720 William Cheng: Okay, so, so people like interactivity. So it says, Well, what if we, you know, make it into a multi user time sharing system. So again, one room full of computer. And there's only one computer, we're going to have multiple users sitting 43 00:05:30.960 --> 00:05:36.780 William Cheng: Sitting in front of the computer interacting with you would do with a computer. Okay. They say, Well, that would be a great product. 44 00:05:37.410 --> 00:05:43.590 William Cheng: Okay, so what they did was that they started a project called a time sharing system project they want to fill this multi user time sharing system. 45 00:05:43.860 --> 00:05:52.740 William Cheng: As it turns out, it's a very, very difficult system to build. It's a large monolithic system because at the time the only way they can know how to build audiences and it's about a monolithic operating system. 46 00:05:53.100 --> 00:06:03.810 William Cheng: Okay, lots of people working on there for many, many years. In the end, it's a total flop. Okay, the program manager for this program, I guess you was very famous because he wrote a book. 47 00:06:04.320 --> 00:06:13.770 William Cheng: The book called The Mythical Man Month. So, of course, you know, it's a member of the very sexist term. So, so I guess you know so integral day when they tried to sort of measure 48 00:06:15.930 --> 00:06:21.570 William Cheng: Measure the size of the project. There was, said I, you know, for this particular project. You know how many people, how many months. 49 00:06:22.050 --> 00:06:30.690 William Cheng: Do I have to do the does it take to finish this project manager, for example, you know, a project can be you know 50 men month or and we'll call it 50 people month at these days. 50 00:06:31.350 --> 00:06:37.500 William Cheng: So in that case, if you put 50 people on it would be done in one month, or you can put one person on it and it will take you 15 months. 51 00:06:38.190 --> 00:06:41.670 William Cheng: Okay, so that's the definition of, you know, this people month on memory, right. 52 00:06:41.910 --> 00:06:49.650 William Cheng: As it turns out, when you apply that to software. It doesn't really work that way. Right. Sometimes the war people you put onto a project, the longer it takes to finish the project. 53 00:06:49.980 --> 00:06:53.970 William Cheng: And I'm hoping that your current assignment that you're not experiencing that in your kernel Simon 54 00:06:54.600 --> 00:07:01.980 William Cheng: But so, so he wrote the pitch for the book called The Mythical Man Month, so you know when it comes to software. This particular principle doesn't apply anymore. 55 00:07:02.760 --> 00:07:11.730 William Cheng: Okay. All right, so, so, so, so what happened after this project flop, you know, some people at IBM is sort of notice that IBM actually have to have another piece of technology. 56 00:07:12.180 --> 00:07:18.690 William Cheng: This is called the virtual machine monitor or VM M over here, the project name is close to six CP 67 57 00:07:19.260 --> 00:07:33.030 William Cheng: support multiple virtual IBM 360s or IBM called everything 60 the hardware is Heidi and 360 and the organization is called always 360 so this is one piece of hardware that support multiple IP and 360 software's 58 00:07:33.930 --> 00:07:40.800 William Cheng: Know, multiple IBM 360 operating system. Okay, so you can think about this one machine over here, I can run or 360 another 59 00:07:41.850 --> 00:07:46.530 William Cheng: And so I can run multiple always 360 on top of it. So why do they want a system like that. 60 00:07:46.980 --> 00:07:51.450 William Cheng: Okay, because you know sometimes when customer tried to buy a particular machine, you know, every different 61 00:07:51.840 --> 00:08:01.470 William Cheng: So the operating system can be configured in a different way. So certain kind of configuration is going to be good for certain kind of application and certain other kind of configuration might be good for different kinds of 62 00:08:02.580 --> 00:08:09.720 William Cheng: Different kinds of application. So if you want to have both the best of both worlds. You will use a virtual machine monitor that supports multiple 63 00:08:10.020 --> 00:08:17.490 William Cheng: Or 360s so this way you know the customer can actually use multiple operating system. One of them to run, you know, maybe financial packages and the other one. 64 00:08:17.910 --> 00:08:29.100 William Cheng: Some, some some some other packages. So this way you have the best of both worlds. Okay, so some people look at this isn't as a hey wait a second. What if you instead of supporting always 360 you replace them with CMS. 65 00:08:30.000 --> 00:08:37.290 William Cheng: There so I will have one virtual machine monitor support multiple CMS is now I'm going to end up with a multi user time sharing system. 66 00:08:38.340 --> 00:08:51.600 William Cheng: Okay, so by just combining these two pieces of technology, you're going to have, you know, that the other. The goal of this time sharing project. And that's exactly what IBM did okay so put the state of the two things together, you're going to end up with a working multi user type system. 67 00:08:52.860 --> 00:08:54.270 William Cheng: Alright, so in this guy sort of the picture will 68 00:08:54.720 --> 00:08:58.710 William Cheng: Look like this, right. So this is you know what they have for the architecture for the virtual machine monitor 69 00:08:58.890 --> 00:09:05.700 William Cheng: So this is called VM. And so, by the way, what is the monitor. I mean, today we don't call things monitor in war monitor is a screen. Now is it that way. 70 00:09:05.850 --> 00:09:13.860 William Cheng: So so so in the good old days, if you look up Wikipedia and find out what the definition monitor is you're going to see that a monitor is a synchronization construct 71 00:09:14.070 --> 00:09:20.520 William Cheng: That allows execution entities have to have both mutual exclusion and the ability to wait for certain condition to become true 72 00:09:21.720 --> 00:09:33.180 William Cheng: So what does that sound like to you what a sound like piece where you know muta blog piece of music on large piece of tradition way Peter condition signal Peter engine broadcast. Right. So basically you know your your threat library is going to 73 00:09:34.290 --> 00:09:37.110 William Cheng: Is going to be able to provide the functionality of a monitor 74 00:09:37.290 --> 00:09:46.380 William Cheng: And also your operating system inside the operating system. You have to wait for each other. Yes, threats, you know you had magnetized stuff like that. So this is the operating system. And this is a multi threading library. 75 00:09:47.070 --> 00:09:56.550 William Cheng: Okay, so I'll be here. You know, they call a monitor, because you guys have multiple entities over here. They can wait for each other you know and and they have mutual exclusion, all that kind of stuff. So that's why this is called 76 00:09:56.880 --> 00:09:59.940 William Cheng: Virtual Machine monitor. I mean, today we don't call it a mom to anymore. 77 00:10:00.420 --> 00:10:04.470 William Cheng: So today we actually would call this one. I don't know if you heard of the term is called hypervisor. 78 00:10:04.800 --> 00:10:10.230 William Cheng: Okay, a hypervisor is going to be a piece of software over here that will allow multiple operating systems on top of it. 79 00:10:10.620 --> 00:10:16.320 William Cheng: Okay, so, so we're going to use the word hypervisor and virtual machine monitors or interchangeably to mean the same thing now. 80 00:10:17.070 --> 00:10:22.920 William Cheng: Well, so the picture over here is that, you know, he's not a virtual machine monitor over here we're going to run virtual multiple different virtual machines. 81 00:10:23.160 --> 00:10:33.780 William Cheng: Every virtual machine on top of we're going to run a different piece of software. Okay. So, this one might be CMS. Right. This will also see our CMS as well. W. CMS. Then we're going to end up with a you know a multi 82 00:10:35.100 --> 00:10:46.560 William Cheng: multi user time sharing system right if we run the good ol boys. Oh, you know, it always happens is there are 363 6360 or this inherit that you become CP 67 83 00:10:47.730 --> 00:10:53.850 William Cheng: Okay, we can also do mix and match made in one of them are 360 the other way around. CMS and the other two CMS or maybe we're going to 84 00:10:54.270 --> 00:11:01.260 William Cheng: End up running 10 CMS is another 10 always to be 60 they're all configured differently. So that will be the goal for the idea of that filter. 85 00:11:02.070 --> 00:11:12.000 William Cheng: So filters that this virtual machine your technology now. So every one of them is going to run different companies to Sam and on top of the operating system. They will run different kinds of applications now. 86 00:11:13.530 --> 00:11:22.440 William Cheng: Well, as in this case, you know, over here we have a layer over here called the virtual machine. So what kind of abstraction does a virtual machine provide right so the virtual machine is sitting right below the operating system. 87 00:11:22.650 --> 00:11:25.050 William Cheng: So, so what is the opposite thing the virtual machine. Yes. 88 00:11:25.680 --> 00:11:34.410 William Cheng: What the virtual machine. Yeah. So as far as the operating system is concerned, let me declutter this a little bit right for this operating system which could be always 360 or could be the CMS audiences them. 89 00:11:34.620 --> 00:11:38.730 William Cheng: It's sit on top of the virtual machine. So it things that the virtual machine is the real hardware. 90 00:11:39.810 --> 00:11:43.380 William Cheng: Okay. So, therefore, if you ask the question, what options does the virtual machine provide 91 00:11:43.770 --> 00:11:55.080 William Cheng: They provide the abstraction of the real, the real IBM 360 hardware. Right. So as far as the operating system is concerned over here. It doesn't know that is running, running on top of the virtual machine it things that is running on the real machine. 92 00:11:56.010 --> 00:12:04.590 William Cheng: Okay, so, India, the virtual machines this abstraction needs to be so good that the operating system cannot tell the difference whether it's running on a real machine or running inside a virtual shake. Yeah. 93 00:12:06.870 --> 00:12:17.550 William Cheng: All right, so, so there's no ambiguity about the interface the virtual machine monitor must provide it needs to be identical to the real machine that that guess that the organism over here will not be able to tell the difference. 94 00:12:17.970 --> 00:12:21.870 William Cheng: Okay, so we're going to sort of talk about how to actually implement, you know, this kind of architecture. Okay. 95 00:12:23.520 --> 00:12:33.150 William Cheng: Alright. So before we talk about the implement. So let's clear clarify about the terminology, because you know people actually use virtual machine all over the place, they mean different things. 96 00:12:33.690 --> 00:12:38.130 William Cheng: As far as this cost is concerned, right, you know, the way we're going to be fine virtual machines that 97 00:12:38.520 --> 00:12:41.160 William Cheng: You know, so what is the consumer virtual machine for this class. 98 00:12:41.370 --> 00:12:49.200 William Cheng: Is that we're going to run one operating system inside another operating system. Right. So if you look at this picture over here, we are running OS. A or A spiel S3. 99 00:12:49.410 --> 00:12:56.640 William Cheng: On HAVA. This is, you know, this is the reality is, is that the virtual machine monitor is the Robin is too simple. The real machine. It's sitting on top of the real hardware. 100 00:12:56.850 --> 00:13:04.680 William Cheng: Well, all of these, you know, the operating system over here. They run on top of the virtual machine which on top of on top of the real operating system. 101 00:13:05.610 --> 00:13:14.820 William Cheng: Okay, so we only consider a consider a virtual machine. We have one operating system running on top of that, the operating system by which is what you have been using in Virtual Box right if you're in Virtual Box. 102 00:13:15.300 --> 00:13:27.270 William Cheng: You are having Ubuntu 16.04 running on top of what write up a Windows machine is running on Windows. If you have a Mac OS X is running on top of the Mac OS X. So when you're using Virtual Box, you are actually using a virtual machine according to our definition. 103 00:13:28.200 --> 00:13:34.440 William Cheng: That. So we're going to run over here it says run not simulate emulate. Okay, well actually going to execute 104 00:13:35.700 --> 00:13:43.950 William Cheng: Execute one operating system, you know, inside of an operating system. Right. So we went around OS X is inside or uncover or is why 105 00:13:44.340 --> 00:13:50.520 William Cheng: Okay, so this is always why over here is going to be the virtual machine monitor right and then OS X over here is going to be CMS. 106 00:13:51.150 --> 00:13:58.860 William Cheng: Is going to be 360 that. So we're going to refer to OSS as the guest operating system at all, as well as the host operating system. 107 00:13:59.070 --> 00:14:03.930 William Cheng: Because inside of host, you can have many guests raspberries, like you know you're renting out your room you know your your your 108 00:14:04.350 --> 00:14:09.000 William Cheng: Your house to to multiple people you have multiple guests. You know that they're both living your house. 109 00:14:09.480 --> 00:14:17.640 William Cheng: Okay, so therefore the obvious is that my the bottom is known as the host Afghanistan and you know the the one that are running on top there, the guest operating system then 110 00:14:18.120 --> 00:14:28.740 William Cheng: We follow this terminology from VMware VMware if you are installing, you know, VMware on top of your windows 10 then your windows 10 is host happiness is an inside the 111 00:14:29.730 --> 00:14:38.700 William Cheng: Inside the VMware, I guess the VMware workstation and the Oracle call it the Virtual Box. Right. So inside of inside of you run the guest operating system now. 112 00:14:39.480 --> 00:14:48.750 William Cheng: Right, so a virtual machine is not an OS simulator. It doesn't emulate the operating system because we need to execute the case. Often the system on the real CPU directly 113 00:14:50.010 --> 00:14:55.710 William Cheng: Okay, so. So again, if you go back to this picture over here, this operating system is actually running on the real hardware. 114 00:14:56.340 --> 00:15:08.190 William Cheng: Okay, so even though there's an interface over here that goes to the virtual machine interface, it thinks that the virtual machine is the is the real hardware, but the code inside these companies is that they are actually executing on the real machine. 115 00:15:09.240 --> 00:15:14.520 William Cheng: Okay, so. So again, that's our definition of a virtual machine. There's another way to do it is that, you know, 116 00:15:15.030 --> 00:15:22.110 William Cheng: If you look at your current assignment, you're running Q em you so Q. Yum. You can act as a virtual machine but qu is a CPU emulator. 117 00:15:22.440 --> 00:15:30.900 William Cheng: Well, so in that case, we can't really call it a virtual machine on the architecture, because you know every instructions over here. You're executing the emulator on to em you 118 00:15:31.290 --> 00:15:41.340 William Cheng: They actually it was complicated. You can use them as a virtual machine. You can also use them as a CPU emulator, but I think, you know, for our current. Oh, Simon. They're actually used as a CPU emulator. 119 00:15:41.880 --> 00:15:45.210 William Cheng: And so therefore, what you do something like that, then it's no longer call a virtual machine. 120 00:15:47.820 --> 00:15:53.820 William Cheng: So we're going to make the guest operating system thing that's running on the real hardware, because they are executing instruction on the real hardware. 121 00:15:53.970 --> 00:16:03.060 William Cheng: But in reality is running inside a virtual machine. Right. Okay. And so in this case. Yeah, they're executing on real hardware. So what does it mean to run inside the inside a virtual machine. 122 00:16:03.480 --> 00:16:15.300 William Cheng: Yeah, so, so, so, so, so what we mean by that, by, by the virtual machine is that the CO and the data structure that you put inside a host operating system so that you can run the guest operating system is called the virtual machine. 123 00:16:16.230 --> 00:16:27.960 William Cheng: Okay, so, you know, so, so this lady over here, virtually over here is belongs. Is it cold and data structure inside a real operating system so that they will allow the guest operating system over here to 124 00:16:28.380 --> 00:16:36.480 William Cheng: Run inside of host operating system, who has or whatever it takes, include code include data structure. So those are part of the virtual machine. Okay. 125 00:16:37.440 --> 00:16:45.960 William Cheng: All right. The last point over here is that the host operating system like the example that I gave, right, the host operating system on your desktop is going to be windows 10 is gonna be Mac OS X. 126 00:16:46.500 --> 00:16:56.790 William Cheng: So that will be the general purpose opening says, then you can also have the host optimists tend to be a specialized operating system like in the case for IBM the IBM the specialized offerings as the virtual machine monitor 127 00:16:57.480 --> 00:17:06.780 William Cheng: Okay, so that was old technology they actually use this, you know, especially the operating system today, you know, mostly even a see a general purpose albinism as the host sister, then 128 00:17:08.850 --> 00:17:15.630 William Cheng: There are also two types of virtual domain, maybe more than two types of virtualization technology. One is called pure virtualized 129 00:17:16.200 --> 00:17:21.900 William Cheng: Pure virtualization. So when you talk about pure virtualization. That means that the guest operating system is unmodified 130 00:17:22.530 --> 00:17:37.530 William Cheng: Okay, so when you install Ubuntu 16.04 into Virtual Box. Did you modify Ubuntu 16.04 well no right you download one to 60 month worthwhile for that the ISO file that the ISO file. Those are the one that you can actually install it directly onto hardware. 131 00:17:38.580 --> 00:17:47.190 William Cheng: OK. So again, the Ubuntu 16.04 the ISO file, you can actually install it on on real hardware and that will actually give you an operating system that you can run 132 00:17:47.340 --> 00:17:53.400 William Cheng: Right. So when we install it into Virtual Box. We use exactly the same file. So therefore, the guest operating system is unmodified 133 00:17:53.910 --> 00:17:57.570 William Cheng: Okay, so when I guess. Obviously this is a modify is called pure virtualization. 134 00:17:58.200 --> 00:18:05.220 William Cheng: Okay. So this guy is the guest operating system thing that is running directly on the hardware I we install the same, same, same guess obviously them. 135 00:18:05.400 --> 00:18:11.250 William Cheng: Either directly on hardware or the directly inside a Virtual Box. There's no way for the system to be able to tell the difference. 136 00:18:11.760 --> 00:18:20.670 William Cheng: Okay, so in that case, we're doing pure virtualization. Okay, there's another approach know as the virtualization over here, in this case the guest operating system is modify 137 00:18:21.060 --> 00:18:30.600 William Cheng: Okay, so we're going to take the original bunch of 60.04 ISO file and we're going to change it so that this the new guest operating system can only run inside the virtual machine. 138 00:18:31.110 --> 00:18:38.040 William Cheng: Okay, if you take this out you if you take this is sofa and if you try to install it on a raw hardware, you know, the obvious is that when I work 139 00:18:38.400 --> 00:18:46.740 William Cheng: Okay, so this is no as pal virtualization. So in this case, the modified organism can only run inside a virtual machine. If you try to put it on sort of real hardware, it doesn't work. 140 00:18:47.670 --> 00:18:52.380 William Cheng: There, there's also something else. So then in that case, we won't call it a virtual machine. 141 00:18:53.250 --> 00:18:58.860 William Cheng: OK. So again, virtual machine over here because of all this requirement. The only two is doing. One is pure virtualization. 142 00:18:59.340 --> 00:19:06.630 William Cheng: The other one is parallel virtualization. So when you go on, you know, if you have somebody says we're working on virtual machine, you got to be able to sort of figure out what kind of virtual machines. They're working on 143 00:19:07.020 --> 00:19:14.520 William Cheng: Okay, whether they are using pre adverse ization or they're doing power versus Asian or they're doing something else. They're not running an operating system is not operating system. 144 00:19:14.790 --> 00:19:25.800 William Cheng: Right. So in that case, you know, according to our class. We don't call that a virtual machine, even though other people might my mom I call that a virtual machine. Okay. Alright, so, so please make sure you understand, you know, all these this this thing show 145 00:19:29.730 --> 00:19:37.620 William Cheng: Alright, so let's talk briefly about how to actually implement a virtual machine. So we're going to talk about a very, very high level concept, how to implement virtual machine. 146 00:19:38.340 --> 00:19:48.570 William Cheng: Yeah, so this the solution over here is this is going to sound very, very simple. Right. I don't really want to oversimplify this even though the concept is very, very simple. In the end, it's very tedious to get this to work, you don't 147 00:19:49.860 --> 00:19:51.000 William Cheng: Take a lot of, you know, 148 00:19:53.190 --> 00:20:04.470 William Cheng: You know, a lot of time and very detailed implementation to get this work. Right. But the basic idea is very, very simple. We're going to run the entire virtual machine in the user mode of the real machine. 149 00:20:06.540 --> 00:20:15.930 William Cheng: Okay, so. So in this case, you know, the entire virtual machines are basically went to run the guest operating system and the application in the user mode of the real machine, right. So on the left hand side over here. I'm going to have the real machine. 150 00:20:16.500 --> 00:20:25.290 William Cheng: Guys, again, conceptually, I'll be getting the real machine. There's a real operating system. And there's a user space. So the real operating system over here is the one is running the virtual machine monitor 151 00:20:25.800 --> 00:20:36.540 William Cheng: Okay. So inside the user space over here we're going to run the virtual machine, right. So on the right hand side over here, you can see that over here. Here's a picture of the virtual machine right as far as the guest operating system is concerned, this is the real machine. 152 00:20:37.320 --> 00:20:43.470 William Cheng: Okay. So on the right hand side over here. This is what the application thing that the machine. Yes. And also what the guests. Obviously, some of the things 153 00:20:44.130 --> 00:20:55.200 William Cheng: The machine. Yes. Right. So we feel we have a virtual machine. And when it gets operating system running on top of it. Okay. So in this case, both the guest operating system and the application they run in the user space of the real machine. 154 00:20:56.310 --> 00:21:04.770 William Cheng: So this sounds really weird. Now we have an operating system is supposed to run in the privilege mode of real machine, but now it's going to run in the user mode of the real machine. 155 00:21:06.060 --> 00:21:07.740 William Cheng: Or I can just, you can just even be done. 156 00:21:08.820 --> 00:21:11.490 William Cheng: Okay, so that's what we're going to talk about how to actually get this to work there. 157 00:21:11.790 --> 00:21:20.460 William Cheng: Alright, so we are memorizing the privilege mo of the real machine, while the entire you know the guest operating system run entirely in the user space of the real machine now. 158 00:21:21.030 --> 00:21:25.230 William Cheng: So I'll be here says, one of the things that you need to be able to do is that the VM VM is 159 00:21:25.770 --> 00:21:33.750 William Cheng: The opposite of what the real machine, it needs to keep track of every virtual for every virtual machine, whether it's in the virtual privilege mode or in the virtual user well 160 00:21:34.050 --> 00:21:40.590 William Cheng: I mean, so now the terminology going to get a little uglier over here, right, because what we talked about, you know, the guest operating system is going to run inside of privilege more 161 00:21:40.800 --> 00:21:46.650 William Cheng: But in this case is the privilege of the virtual machine. So we're going to call this privileged privileged mode, the virtual privilege mode. 162 00:21:47.430 --> 00:21:52.350 William Cheng: Okay. Because the real privilege know is actually, is that a real machine that's where VM is running off so therefore we need to give a 163 00:21:52.620 --> 00:22:02.100 William Cheng: Different name, you know, for the guests up and this is that the guess I'll reason is going to run inside the virtual privilege mall and also the user program. They're going to be running in the virtual user mode. 164 00:22:02.670 --> 00:22:06.330 William Cheng: Okay, what about the real user melt the real user mode is where you run the virtual machine. 165 00:22:07.200 --> 00:22:15.420 William Cheng: That. All right, so, so, you know, so one VM M over here can support multiple virtual machines. Oh, here's one virtual machine, there's a two. There's three maybe there's 10 of them. 166 00:22:15.870 --> 00:22:25.050 William Cheng: Okay, for every virtual machine, the VMware has to keep toggle whether every virtual machine is in the virtual privilege mo or individual user mode. Okay, so, so, can this be done. 167 00:22:26.910 --> 00:22:30.840 William Cheng: Okay, it's over here. So let's take a look. Declutter this a little bit right you know 168 00:22:31.590 --> 00:22:37.620 William Cheng: So so so let's say that you know we're in the in the virtual user mode over here. And then we're going to sort of execute a 169 00:22:37.890 --> 00:22:42.960 William Cheng: Machine structured Man We're gonna make a system called we're going to make the rice. It's them call via Wi Fi over here, right. 170 00:22:43.260 --> 00:22:49.530 William Cheng: This is, this is a call. So again, right, is a sin thin wrapper around the track machine structure we actually go to troubleshooting instruction, what happens 171 00:22:50.070 --> 00:22:54.420 William Cheng: Next, so there's a trap machines right here, right, you can execute. Right. So, this you know again. 172 00:22:54.660 --> 00:23:01.620 William Cheng: This instructions execute on my real hardware. So, therefore, is actually on a real Harwell over here. When you execute a time machine, you start getting the real hardware live in 173 00:23:02.010 --> 00:23:10.350 William Cheng: While you're traveling through the real operating system. So definitely going to come into the virtual machine monitor. I'll be here. So now you're executing code over here instead of trap handler I we saw you know 174 00:23:11.220 --> 00:23:18.180 William Cheng: A few weeks back. You don't want to trap handled or cold look like that. But now it's executing. Is that a real opportunities there so executing instead of emf 175 00:23:18.750 --> 00:23:20.340 William Cheng: Okay, so where does the want to go. 176 00:23:21.300 --> 00:23:28.560 William Cheng: Okay, when I make the right system called over here. Where does this supposed to rewrite it supposed to read the kernel version of the right inside a guest operating system. Right. 177 00:23:28.710 --> 00:23:34.170 William Cheng: So he's still getting the way we sort of think about is that inside it gets obvious is that there is k, right, which is the kernel version of the right 178 00:23:34.410 --> 00:23:42.900 William Cheng: There. So when we make the racism call we will try to get here. But now, instead we are in the you know somewhere inside virtual machine monitor. Okay, how can we get here. 179 00:23:44.550 --> 00:23:50.070 William Cheng: I mean, if you look at this picture right we are inside VMware, we are, how do we get okay right we're going to make an appt call to go to K. Right. 180 00:23:51.120 --> 00:23:59.280 William Cheng: Right, because the okay right over here is going to be in the user space of the real machine. So in this case, all we have to do is to make up call. And then I'm going to end up. Okay. Right. 181 00:24:00.270 --> 00:24:05.310 William Cheng: Okay, so this can be done right. So we tried in the virtual machine monitor version. It says, Oh, you want to go to K right over here. 182 00:24:05.490 --> 00:24:15.180 William Cheng: I'm going to make up call. And then I'm going to guess happens to them. So in this case, the virtual machine monitor good also remember that for this virtual machine. Now it's executing inside the virtual privilege mode. 183 00:24:16.530 --> 00:24:24.300 William Cheng: Okay. So, therefore, you know, will you, will you make a transition from the virtual user multiple virtual privilege Mo, the VM. And we'll, we'll have know about it because it goes to VM M. 184 00:24:24.960 --> 00:24:30.480 William Cheng: Okay, what about, you know, will you finish the K rod operational via we need to return to the user space polka, what would you do 185 00:24:30.990 --> 00:24:36.060 William Cheng: Okay, so, India, and over here. You're going to execute the I returned machines Joshua. I mean, again, we're going to pretend that we're running into out 186 00:24:36.420 --> 00:24:44.340 William Cheng: Again, but in reality we're talking about IBM 365 IBM three seats 360 might be a different instruction, but since we're familiar with I return, we're going to pretend that will actually return 187 00:24:45.090 --> 00:24:50.100 William Cheng: Okay, so we're going to execute I return which going to return for this particular instruction is a privilege of structure. 188 00:24:50.670 --> 00:24:57.780 William Cheng: Okay, so therefore, as soon as you execute I inserted guess audiences that since the guests audiences and is executing the user mode of the 189 00:24:58.560 --> 00:25:05.610 William Cheng: Real machine. So this instruction will be executed in the real hardware. So in this case, again you will end up causing a trap into the virtual machine monitor 190 00:25:05.850 --> 00:25:09.600 William Cheng: And then once you get into the virtual. Come on over here the virtual is, you know, why, why am I here. 191 00:25:09.900 --> 00:25:20.310 William Cheng: Oh you execute the I returning structure. So in this case, since the virtual machine monitor know that it was inside the virtual privilege Mo, so he knows that he needs to return back into the user user space application. 192 00:25:21.180 --> 00:25:28.770 William Cheng: Whereas, in this case, how do you do it right. So again, the idea here is that if you are Intel inside the virtual machine monitor. We're going to execute the I return over here. 193 00:25:28.980 --> 00:25:41.280 William Cheng: In the real privilege mouth. Right. So this guy is going to set things up so that we can go back to the user space program. Okay. Yeah, right. Before we do that inside VMware, we can also make a note to say now for this virtual machine. Now it's going to be in the virtual user mode. 194 00:25:42.600 --> 00:25:53.160 William Cheng: Okay. So, using this is this very, very simple example. I hope that have convince you that is possible for the virtual machine monitor to know for every virtual machine, whether it's executing individual user mode or in the virtual privilege. 195 00:25:53.670 --> 00:25:57.990 William Cheng: Okay, because any transition has to go through the virtual machine monitor right 196 00:25:59.490 --> 00:26:06.420 William Cheng: All right, so this is one of the criteria we here at the Virtual Machine Manager needs to know you know what what what's actually going on. Okay. 197 00:26:09.630 --> 00:26:12.510 William Cheng: Alright, so let's take a look a little more detail, I would say that, you know, 198 00:26:13.380 --> 00:26:21.120 William Cheng: We try to executing such an excellent a real hardware. Again, I'm going to go back to this picture over here, there are many, many virtual machine right here. We only look at one of them. 199 00:26:21.840 --> 00:26:31.800 William Cheng: Yeah, so when you execute an instruction in the user space program over here. Again, you're actually getting called right here. We actually do that inside a real hardware. So the picture. I'm going to draw is going to be like this. 200 00:26:32.490 --> 00:26:39.720 William Cheng: Oh god, I'm going to point to the user red arrow here. The point of the, the real hardware to set out of the red arrow over here is going to be executing on the real hardware. 201 00:26:40.440 --> 00:26:47.310 William Cheng: OK, so again this is wonderful requirement for using our virtual machine everything inside the user space over here. They are executing code that you know 202 00:26:49.230 --> 00:26:55.830 William Cheng: There's gonna be no CPU emulation or operating system Isla emulation of year we're going to execute them directly on hardware. 203 00:26:56.280 --> 00:27:01.140 William Cheng: Okay. So in this case, when you are running code over here in the application program. 204 00:27:01.650 --> 00:27:09.600 William Cheng: Okay, whether you are running on a virtual machine or not running a virtual machine. The speed is going to be completed the same because the code that you actually, you know, we hear directly actually on the hardware. 205 00:27:10.500 --> 00:27:15.030 William Cheng: Okay, so this is one of the reason virtual machine is actually pretty popular because you don't lose any speed. 206 00:27:15.780 --> 00:27:24.210 William Cheng: Right, you know, whatever the color you actually go over here. If you actually look directly on hardware or, you know, running on top of virtual machine. There's no speed difference. So in this case, you going to end up with good performance. 207 00:27:24.990 --> 00:27:32.640 William Cheng: Okay, so from the application perspective, there's no difference running VM or running hardware, because the code execute directly on hardware that 208 00:27:33.450 --> 00:27:41.700 William Cheng: Alright, so again, this is where I make my knows that this, you know, on the right hand side over here, you can see that it sort of looks like our Colonel assignment, right, we have the application, which is your hello program. 209 00:27:41.940 --> 00:27:51.360 William Cheng: Run on top of the weenies awkwardnesses, of which the guest operating system which run on top of Q em you who looks like a virtual machine which runs on Linux Ubuntu 16.04 210 00:27:51.630 --> 00:27:58.410 William Cheng: And again, if you install bundles 16.4 directly or hardware and this will be on your hardware. But typically, again, we run it inside a virtual machine. 211 00:27:58.530 --> 00:28:04.470 William Cheng: So at the bottom over here is going to be virtual machine and the virtual machines running on the host option is this, that, and the host audiences and wrong. The real hardware. 212 00:28:05.340 --> 00:28:15.030 William Cheng: Okay, but if you install Linux and directly on the hardware that we're gonna have this picture. But again, these two things are totally not equal because he me over here is not a virtual machine. 213 00:28:15.570 --> 00:28:22.680 William Cheng: Okay QAM you as an emulator for the x86 instruction set because. Okay, what does that mean to be an X86 emulator. 214 00:28:23.040 --> 00:28:32.580 William Cheng: That, that means that inside kill em you they pretend to be an X86 CPU. So for example, you know what's inside SABC CPU right there's a registered right there's a yes register. 215 00:28:33.360 --> 00:28:41.550 William Cheng: There so inside Q em you yeah x is going to be a data structure. Okay, so when you're executing instruction, you know, say move out. 216 00:28:42.090 --> 00:28:53.100 William Cheng: You know, dollar one comma yeah X that. What does that mean, right, when this case when you execute it on the real hardware inside the hardware. I'll be here. There's a year to register and you put one in there. 217 00:28:53.790 --> 00:29:02.880 William Cheng: Okay, if you are running using qu em you in that case. Yeah, x will be a data structure and what it will do is that they will, you know, look at the assembly code over here and then any will emulate every structure. 218 00:29:03.360 --> 00:29:11.310 William Cheng: Okay, so if you see the instruction like this. What it will do is that it will put the the the numerical constant one inside this data structure know as yes 219 00:29:11.670 --> 00:29:22.020 William Cheng: Okay, so that's how you emulate the CPU, because the CPU, the entire CPU all the register, whatever that says that the CPU, they are all there. You know, they are they all have representation inside qu 220 00:29:22.860 --> 00:29:30.000 William Cheng: Okay. And when you execute machine structure, you're going to manipulate these data structure as opposed to manipulate the the register inside. Inside the actual CPU. 221 00:29:31.020 --> 00:29:42.570 William Cheng: Or is it again, even though this picture and this picture look very similar in reality they're very different. Okay. On the right hand side over here, this is one called virtual machine over here. This is not a virtual machine. Yeah, because it's done by CPU emulator. 222 00:29:44.130 --> 00:29:52.260 William Cheng: Oh I one of your application execute a true I put this instruction, just like the example that we saw before I actually traveling instruction which could be a system called or maybe you 223 00:29:52.530 --> 00:30:00.450 William Cheng: Know you run to a page for maybe divide by zero or something like that. Right. So again, the instruction that you execute what we hear inside the application. He will 224 00:30:01.560 --> 00:30:07.800 William Cheng: It will be executed directly on hardware. So if you make the trap you know if you actually have a time machine instruction, where should I go 225 00:30:08.400 --> 00:30:15.000 William Cheng: Okay. So we mentioned before, you need to go into the end of a virtual machine monitor over here because because you know we execute a trap, you're gonna end up 226 00:30:16.050 --> 00:30:19.440 William Cheng: Actually yes you traveled the real hardware. So you're gonna end up in the real operating system. 227 00:30:19.860 --> 00:30:25.440 William Cheng: Okay, but again, where does it want to go. Right. Well, if we are running on the real hardware than it needs to get into the to the 228 00:30:26.130 --> 00:30:27.300 William Cheng: Again, the guest operating system. 229 00:30:27.900 --> 00:30:36.780 William Cheng: Okay, so what we need to do is that you know you know we we get into the virtual machine monitor, but our but what we're supposed to go is to get into the guest operating system. 230 00:30:37.080 --> 00:30:47.040 William Cheng: Okay, we've mentioned before, you know, this needs to be done using up call me in reality is going to be a little more complicated because we need to go through the virtual machine. So it looks like there's a one level of indirection. 231 00:30:48.060 --> 00:30:54.090 William Cheng: That so so yeah we execute a machine instructing you're going to be hardware and then you know this travel we deliver 232 00:30:54.270 --> 00:31:02.490 William Cheng: Into the virtual machine monitor and then what you try to do is that you try to deliver this trap to the guest operating system because instead of guess audiences them. There's a trap handler. 233 00:31:02.850 --> 00:31:07.380 William Cheng: right inside because obviously I'm over here. There's a trap handler and the goal is to actually reach there. 234 00:31:07.800 --> 00:31:16.500 William Cheng: Okay, but we don't want to go there directly want to go there indirectly through the virtual machine, the virtual machine data showed you over here. Why, what, why do we want to do that. 235 00:31:17.010 --> 00:31:24.480 William Cheng: Okay, because this way, our virtual machine virtual machine implementation over here can be independent of the actual virtual machine. 236 00:31:25.830 --> 00:31:32.130 William Cheng: Now, so I'll be here you know VM and needs to figure out which VM is currently executing. Right. So why don't you try things out of a VM over here. 237 00:31:32.310 --> 00:31:38.730 William Cheng: There are many, many virtual machines over here. So, so in this case. How do you find out which virtual machine actually cost the cost of trap. 238 00:31:39.420 --> 00:31:43.470 William Cheng: OK. So again, if you think about your current one. There's a global variable called current process. 239 00:31:43.800 --> 00:31:52.890 William Cheng: Right. So in this case, this is kind of like a process. Right. So basically we have multiple processes over here. So when you try things that obviously that we should know you know which processes, when it comes to fall. 240 00:31:53.640 --> 00:31:57.000 William Cheng: Okay. In Colonel one you have current product that's how you you know which process. 241 00:31:57.420 --> 00:32:04.170 William Cheng: caused the fall and now we made. Maybe he started kind of we're going to have a global variable called the current virtual machine and this way we know which virtual machine. 242 00:32:04.620 --> 00:32:12.360 William Cheng: Cost the fall. Okay, so once we determine that this is the virtual machine that caused the fall, then we need to deliver you know this particular trapped into the guest operating system. 243 00:32:12.870 --> 00:32:25.830 William Cheng: There. So we need to. So we need to deliver this trap in a virtual machine independent way. So in this case, what do we do, right, we need to make an indirect call over here using the data structure and code inside the virtual machine so that it will actually make a 244 00:32:26.640 --> 00:32:29.220 William Cheng: sizzle. This is where I'm making an indirect up call. 245 00:32:30.420 --> 00:32:35.790 William Cheng: Then we're going to call a function indirectly inside a virtual machine so that you will actually maybe I'll call into the guest operating system. 246 00:32:36.870 --> 00:32:43.290 William Cheng: OK. So again, go over here is that, again, you know, we see the concept, you know, over and over again. We need to be independent. So what do we need to be independent, while 247 00:32:43.650 --> 00:32:51.870 William Cheng: Our virtual machine monitor is going to be the opposite where the real machine. So whatever services that we invoke in the user space, we need to do it in a 248 00:32:52.890 --> 00:33:01.710 William Cheng: Yeah, so sorry in Japanese as an independent way. Okay. So in this example, we're since we're implement a virtual machine. We want the delivery over here to be done, you know, 249 00:33:02.610 --> 00:33:13.650 William Cheng: To be done to be independent of exactly what virtual machine is OK. So again, these virtual machines over here, we need, how we have one virtual machine for or 360 need to have one virtual machine for CMS, we need one. 250 00:33:14.610 --> 00:33:21.720 William Cheng: regime for different kind of guess operating system. So the delivery mechanism over here needs to be done in a virtual machine independent way. 251 00:33:22.230 --> 00:33:28.290 William Cheng: Okay, so that would be ideal right now. So, therefore, what we need to do is that, you know, inside the virtual machine. 252 00:33:28.740 --> 00:33:36.480 William Cheng: So, so again, what's inside a virtual machine or as the code and data structure so that it will allow you to go into the users could go into the guest operating system. 253 00:33:36.930 --> 00:33:44.340 William Cheng: You know when you try to make that up. I'll call you need to make it in a you know you're using a virtual machine independent method that 254 00:33:46.200 --> 00:33:54.990 William Cheng: Right over here. Yeah, so, so again, without the other, the virtual machine or without the virtual machine, the application was simply trap directly right into where the supposed to be right so now 255 00:33:55.290 --> 00:34:02.670 William Cheng: You know this is going to be a lot a lot more involved because you need to come into the virtual machine monitor over here. And then what it would do is that it will look at the data structure and the code. 256 00:34:02.910 --> 00:34:11.700 William Cheng: Inside. So again, there's going to be, you know, probably more for them or something like that inside the virtual machine over here so you can actually make an indirect call to make an alcohol into the guest operating system. Yeah. 257 00:34:13.230 --> 00:34:20.520 William Cheng: All right. So over here, there's a comment. Right. This one, he comes out offering system using us using, you know, using a trap. What about interrupt. 258 00:34:21.030 --> 00:34:30.750 William Cheng: OK. So again, Rob is going to get delivered in the same way, right, if we get a highway interrupt. We're going to get inside the virtual machine monitor over here. Then again, we need to sort of figure out which virtual machine that we need to deliver it to 259 00:34:30.960 --> 00:34:40.920 William Cheng: And then we need to actually make an indirect call over here to make it out call into the system. OK, so the guess obviously the movie will be we will look like as they're 260 00:34:41.700 --> 00:34:47.490 William Cheng: Actually getting a interrupt right because remember the guess obviously some things that are runs on the real hardware. So when it starts and I 261 00:34:48.690 --> 00:34:53.550 William Cheng: Started I operation on the bus, he will, you know, it's expecting that eventually you will get an interrupt. 262 00:34:54.000 --> 00:35:02.190 William Cheng: OK. So again, when you get an internal, private right it's going to ask you to interrupt service routine. So now we also need to make it up call into the interrupt service routine to fake and 263 00:35:03.480 --> 00:35:03.750 William Cheng: Then 264 00:35:06.120 --> 00:35:16.950 William Cheng: Alright, so the virtual machines at this picture over here. So, once these that virtual machine right again it's cold and data structure. What kind of data structure, right. So there needs to be, you know, sort of representation of all the virtual devices. 265 00:35:17.250 --> 00:35:22.170 William Cheng: The virtual devices are the virtual CPU the virtual disk, the virtual keyboard, the virtual I'm in the virtual everything 266 00:35:22.620 --> 00:35:27.030 William Cheng: Okay, we need to have representation over here inside a virtual machine. So this way you know what stay there. Yeah. 267 00:35:27.690 --> 00:35:36.690 William Cheng: OK. So again, the data structure and the code that represent all these different hardware components there. The one that makes up the virtual machine and also there will be able to deliver trap. 268 00:35:36.930 --> 00:35:42.720 William Cheng: Into the guest operating system in a virtual machine independent way right so yeah he's that every different kind of virtual machine, there's gonna be some 269 00:35:42.960 --> 00:35:56.970 William Cheng: Specific code so that when you try to deliver you know these trapped in the guest operating system. It can be done in the VM man using a virtual machine independent way or as well. Again, we see how that's done this using polymorphous is over here we're going to use the same trick, right. 270 00:35:58.950 --> 00:36:10.470 William Cheng: Alright so yeah I'm talking about really high level stuff right the actual detail is actually very tedious guys with the employment of virtual machines. A lot of work. Okay, but sort of conceptually, you can sort of see that this can actually work out. Okay. 271 00:36:14.190 --> 00:36:18.570 William Cheng: So know that most instruction in the trap handled execute on not privileged 272 00:36:18.810 --> 00:36:26.250 William Cheng: Okay, so you're traveling to the operating system over here and now and the robbery. Right. So, so you're coming to the obviously them over here using a racism call 273 00:36:26.430 --> 00:36:32.460 William Cheng: We're going to reach the code. Okay. Right. Right. So your winnings, Colonel. What is the key right look like, right, so remember there to 274 00:36:32.790 --> 00:36:38.730 William Cheng: Know your internal three. There's a sis. Right. And then there's also do right, they're all kernel version of some kind of a right 275 00:36:39.420 --> 00:36:52.410 William Cheng: There also the special devalue especially device right or something like special file right oh, all these things are different version of the kernel version of the right function. Well then, so if you don't get a code over there are the instruction that you're executing. Are they privileged 276 00:36:53.520 --> 00:36:58.320 William Cheng: They think about your kernel to co when you try to implement do right okay is the code privileged 277 00:36:58.980 --> 00:37:09.570 William Cheng: Okay, so you see that the code is actually not privileged and also when you're doing Colonel three were you doing sister right over here. So you're going to see that you know all this code over here the handle the trap. Most of them are actually not privileged 278 00:37:10.800 --> 00:37:16.650 William Cheng: Okay, because if they are privileged and pretty much everything that you're doing is that it gets audiences me and I tried into the VM Matty gonna come back over here. 279 00:37:16.890 --> 00:37:21.840 William Cheng: Then in this case you are you know your virtual machine will be really, really slow. So we're actually very lucky. 280 00:37:22.050 --> 00:37:30.750 William Cheng: That you know most of the instruction in a trap handler they are actually not privileged so therefore they will be executing in the user mode of the real machine perfectly happily. 281 00:37:31.770 --> 00:37:40.170 William Cheng: Okay, there will be running the user Monrovia, they don't need to tap into the Vienna over here. So they will be executing at full speed inside against happens is that man that's exactly what we want. 282 00:37:40.770 --> 00:37:46.080 William Cheng: Okay, so that's why even when we're using a virtual machine technology, you know, in the end, things are actually pretty fast that 283 00:37:48.420 --> 00:37:55.650 William Cheng: You know clearly all these instruction can run in the rum rum foolish mo. Right. So most of the instruction in the tripod little I can do right or something like that. What do we do, right. 284 00:37:55.800 --> 00:38:06.600 William Cheng: We we we do pointer manipulation, we do, you know, add, subtract, multiply, all that kind of stuff. All these things are non privilege. Right, so therefore the SU directly on the hardware and there's gonna be no problem. 285 00:38:06.990 --> 00:38:15.450 William Cheng: That so I'll be here. So sort of is sort of begs the question, what type of code must execute inside of Polish mouth. Okay. 286 00:38:16.260 --> 00:38:28.980 William Cheng: And what if they are actually not privilege. Right. So, for example, the instruction that we saw before I return. Right. So again I return is the x86 and structure we're gonna sort of pretend that on the IBM. They have a similar instruction. Yeah. What if this instruction is not privileged 287 00:38:30.630 --> 00:38:41.280 William Cheng: OK. So again, you know, where do you execute I return. Right. You actually I returned inside it gets operating system. When you're ready to enter into user space. If this instructions over here. It's not privileged, what's going to happen. 288 00:38:42.330 --> 00:38:50.640 William Cheng: Okay, so when you execute this instruction instead of guess operating system since it's in user mode and if it turns out at this church is not privilege, then the wrong things going to happen. 289 00:38:51.840 --> 00:39:02.820 William Cheng: Okay, so, so, so this particular insertion over here, you know, as we as we know for sure that this instruction opiates privilege. So, therefore, you can actually manipulate a bunch of registered over here instead of CPU and then 290 00:39:03.930 --> 00:39:10.350 William Cheng: They can return back to the user space, right. So you're going to disable you know Rob and include disable name Rob is something that's supposed to be done inside the Colonel. 291 00:39:10.530 --> 00:39:14.580 William Cheng: But now if you're allowed to do that in the user space program then that case mappings going to happen. 292 00:39:15.270 --> 00:39:27.600 William Cheng: Okay, so, so if you end up your excellent coding is that the user space polo here and then you're manipulating CPU register in the real hardware. So what kind of bad things going to happen. What may be going to end up affecting other virtual machines. 293 00:39:29.040 --> 00:39:36.300 William Cheng: Okay. So, therefore, you know, we're going to be very careful. Right. So even though I sort of described the virtual machine has this really simple technology over here, right, you just use, you know, 294 00:39:36.450 --> 00:39:41.580 William Cheng: You just you polymorphous them and then you can just trapped through the VM. And in the end, there will be something that we 295 00:39:41.820 --> 00:39:54.930 William Cheng: Don't need to worry about, okay, because if one of these your provisioning instruction. If it turns out not to be privileged, then in that case, we're going to cause the virtual machine to do the wrong thing. Okay, so in the next part of today's of this is where we're sort of 296 00:39:56.880 --> 00:40:03.330 William Cheng: We're going to talk a little bit about, you know, what kind of instruction has to be privileged otherwise we're going to cause trouble is that a virtual machine. Yeah. 297 00:40:04.050 --> 00:40:12.990 William Cheng: Right, so we're gonna come back to that. Pretty soon before that I was also going to talk about how to actually implement I O virtualization. Okay. So, yeah, yeah. How do you do I. Oh, right. So I always 298 00:40:13.740 --> 00:40:19.560 William Cheng: Make a real system called over here right when I make a recent them call again it will execute on the real hardware, it will trap in 299 00:40:19.920 --> 00:40:27.600 William Cheng: We actually the troubleshooting structure, you're going to go to the virtual machine monitor and then there's a real handler. There's a kernel version of the real function over here, right. 300 00:40:27.780 --> 00:40:33.180 William Cheng: So we're going to make transition over here, make an indirect up call to carried over here. So, in that case what will happen. 301 00:40:34.290 --> 00:40:38.280 William Cheng: Then, so again we're going to make all these transaction over here. So, so in this case what will happen is that 302 00:40:38.520 --> 00:40:44.850 William Cheng: When I should take the real desk and we're going to divide them up into virtual disk. So every virtual machine over years. Gonna have a virtual desk. 303 00:40:45.420 --> 00:40:52.860 William Cheng: Okay, you already see that right when you're installing Ubuntu 16.0 for the first thing that it will ask you to do is the how big of a virtual disk. Do you want 304 00:40:53.910 --> 00:41:05.070 William Cheng: Remember, you know we we touch the stove on the sixth floor I they they basically take a hard drive over here, chop them into little virtual drive over here. And one of the virtual drive over here is gonna be represented inside, inside the virtual machine. 305 00:41:05.700 --> 00:41:13.890 William Cheng: Okay, so again you know against by default. We're going to get 10 gigabyte over here for the virtual machine. So, so in that case how, you know, how does actually create a virtual desk. 306 00:41:14.490 --> 00:41:20.190 William Cheng: What on the real you know on the real disco here. What it will do is it'll create a file that's 10 gigabytes in size and 307 00:41:20.430 --> 00:41:29.550 William Cheng: Actually when you run a virtual box over here. They actually asked you to. You want to keep that in one file or you want to chop it into multiple file and have the you know how to describe that ironically also you have a bunch of choices. 308 00:41:30.030 --> 00:41:40.170 William Cheng: So yeah, but the basic idea over here is that on the real disk over here will actually, you know, create a file and this file will be 10 gigabytes in size. Maybe they will be chopped into multiple files over here, but then they represent a virtual disk. 309 00:41:40.770 --> 00:41:47.400 William Cheng: Okay, so when you try to read your desk over here, you basically you tried to read data from the virtual desk. Okay. So, in that case what will happen over here, right. 310 00:41:48.210 --> 00:41:57.420 William Cheng: There so inside you know inside K read over here. Right. You know, the guess obvious ism is going to think that's wrong real hardware. So how do you talk to that this controller. 311 00:41:58.140 --> 00:42:02.280 William Cheng: Okay, you're going to use again I'm going to sort of remind you of Chapter three over here. 312 00:42:02.490 --> 00:42:10.170 William Cheng: The way that you talk to this control over here is that you use a memory map I operation over here. So when you use the memory map I operation over here, what's going to happen. 313 00:42:10.890 --> 00:42:22.260 William Cheng: Okay, since you are in the user space. So you're in the user space of the real machine accessing memory map I oh you know is user user space. But where are they allowed to issue memory map island judging. 314 00:42:22.860 --> 00:42:27.660 William Cheng: Well, the answer is no, that's a privilege instruction. Okay, so therefore this case. But he tried to do 315 00:42:28.380 --> 00:42:40.950 William Cheng: This memory map. I also instruction instead of guess, obviously. But guess what, you know, you can execute a real hardware, you can end up dropping into VM. M But now when you get into VM is that, oh, you know, over here, I'm trying to access, you know, the fake this controller. 316 00:42:42.120 --> 00:42:49.590 William Cheng: Okay, so then how do you do that. Well, I mean, there's really no this controller over here, you know, in the real hardware that's going to is going to completely different from what's inside the virtual machine. 317 00:42:50.010 --> 00:42:54.390 William Cheng: Okay, so everything needs to be fed over here. So in this case, you know, this read operation is trying to 318 00:42:55.140 --> 00:43:00.420 William Cheng: Get this read operation over here. He tried to transfer data from the virtual disk into a fake memory. 319 00:43:00.990 --> 00:43:08.640 William Cheng: Okay, so basically we're going to go to the virtual disk over here transfer data into some kind of a memory that's represented inside the virtual machine over here. 320 00:43:08.850 --> 00:43:17.010 William Cheng: In reality, this data over here is sitting on the desk as a file. So what we need to do is that we do actually copy some far into the buffer over here inside this virtual machine. 321 00:43:18.030 --> 00:43:27.030 William Cheng: Okay. So in this case, you know, all these operations needs to be done inside the virtual machine monitor because there is no handler inside the guest operating system to handle this kind of fault. 322 00:43:27.900 --> 00:43:35.520 William Cheng: Okay, so again this fault is that you execute your memory map island structure in the user space of the real machine. There is no handler for it. Instead of guess options is there, right. 323 00:43:35.700 --> 00:43:42.540 William Cheng: Because when I guess obviously them do something like that it expect that to happen on the real hardware. So therefore, there's no trap handler for such an instruction. 324 00:43:43.530 --> 00:43:54.000 William Cheng: Okay. So in this case, all of the simulation needs to be done inside the virtual machine model so via organs are called a simulation on the on the emulation because we need to emulate the disk controller. 325 00:43:54.990 --> 00:44:03.540 William Cheng: Right, whereas over here. I mean, so yeah, so, so, so, so again that this driver over here. We'll talk to the real hardware. But there's no real hardware. So in this case, they end up fake 326 00:44:04.170 --> 00:44:09.480 William Cheng: OK, so the terminology over here and say that we're going to say that the VM M is that to emulate this particular instruction and this 327 00:44:10.110 --> 00:44:16.800 William Cheng: Is a memory map IO operation. So what it will do is that it will go get data on the real disco be here transfer them into 328 00:44:16.980 --> 00:44:25.890 William Cheng: You know into memory. Is that a virtual machine over here. And then when our operations finish what does it have to do it has to interrupt the guest operating system as if there's a highway interrupt. 329 00:44:27.000 --> 00:44:33.390 William Cheng: Okay, so at the end of the operation over here, what it would do is, I will make a call into the guest services them to execute interrupt service routine. 330 00:44:33.900 --> 00:44:42.690 William Cheng: OK. So again, what do you have any insight interrupt service routine. We're going to unblock a cardinal set and also we're going to start the next I will operation and next operation is going to be another memory map I operation. So, yeah. 331 00:44:42.900 --> 00:44:52.560 William Cheng: We're going to tap into VMware and VMware has to emulate that started I operation and then start transferring data, wait for it to get done. And eventually what it's done over here. Again, it's going to make another call to say, Here's another interesting 332 00:44:54.120 --> 00:45:04.650 William Cheng: Okay, so this is what you have to do in order for you to emulate this kind of IO, right. So, yeah, you know, so, so, so, again, the two things that happens over here. A lot of stuff inside the application instead of guests audiences them. 333 00:45:04.860 --> 00:45:18.300 William Cheng: They can execute directly on the hardware. Well, will you try to you know when the guests offices and execute a memory map I only charging one this case, this particular MY MY OWN SHOW. SHE IS GOING TO GET emulated. Is that a virtual machine monitor 334 00:45:18.750 --> 00:45:27.240 William Cheng: Okay, so in that case it will actually slow down because the entire operation will be emulating inside VMware we no longer directly excuse our hardware we're executing code over here. 335 00:45:27.420 --> 00:45:32.490 William Cheng: Inside the virtual machine monitor while in the real system it will it will actually be a command, you know, to the 336 00:45:32.820 --> 00:45:38.370 William Cheng: To the disk controller and the controller. Why should take over from there. Right. This controller to separate piece of hardware. So they will run 337 00:45:38.670 --> 00:45:47.520 William Cheng: run concurrently with your CPU. But now, since you're inside the virtual machine over here. Yours, you're still executing code instead of CPU, so therefore your virtual machine is going to slow down. 338 00:45:48.540 --> 00:45:55.020 William Cheng: There's again, there's a major difference when you're doing IO, is that your virtual machines actually kind of slowed down quite a bit. Yeah. 339 00:45:56.790 --> 00:46:01.110 William Cheng: So that's sort of a quick introduction of you know what the virtual machine technology is 340 00:46:01.500 --> 00:46:06.600 William Cheng: So as it turns out you know this, you know, this way of organizing the operating system is actually a really good way to go. 341 00:46:06.870 --> 00:46:11.490 William Cheng: Idea and once they invented the virtual machine. Again, we're going to continue to talk about more detail over here. 342 00:46:11.880 --> 00:46:18.750 William Cheng: They found out that there are actually there are many advantages. Okay, so one of them is over here is is know as always debugging and testing. 343 00:46:19.230 --> 00:46:26.520 William Cheng: Before they have these virtual machine. Take a geology. If somebody wants to buy a machine from IBM, they're going to get the whole machine. What if there's a bug inside the operating system. 344 00:46:27.180 --> 00:46:31.410 William Cheng: Okay, there's a button. So the operating system IBM is going to send people, the people there to work on it. 345 00:46:31.590 --> 00:46:39.660 William Cheng: They're going to bring down the entire system. So the system cannot be used by any customer and the IBM engineer is going to work on a sort of debugger and then eventually what is done, it will turn everything back on. 346 00:46:39.990 --> 00:46:47.970 William Cheng: Okay, but now with the virtual machine technology. What can I do. Okay, so what do we do that when somebody buy a machine from IBM IBM is going to sell them a virtual machine. 347 00:46:48.510 --> 00:46:59.820 William Cheng: There. So in this case, what he will do is that you actually run to virtual machine over here one VM on the left and one VM on the right over here. So these VM one VM to they're exactly the same virtual machines. They're running on top of VM M over here. 348 00:47:00.660 --> 00:47:05.850 William Cheng: Yeah, so this one is going to be used by the by the customer. The other one is going to get used by IBM 349 00:47:06.420 --> 00:47:12.870 William Cheng: Okay, so this way when you find a bug inside the operating system. So maybe what you can do that. You can tell the application to say, you know, maybe one application. 350 00:47:13.080 --> 00:47:23.280 William Cheng: shouldn't run anymore because he will hit that bug. While this machine Javier can continue to operate. And then IBM is going to send their engineer or we could work on the second virtual machine which is identical to the first one over here. 351 00:47:23.550 --> 00:47:27.210 William Cheng: That's what you would use your copy all the files over here. Maybe I'm exactly the same. And now the 352 00:47:27.930 --> 00:47:39.330 William Cheng: Engineering over here will be working on the, the same operating system over here, what the customer the machine continue to be operational. So if this is a sort of a bank, they can continue to to to to to stay in business. 353 00:47:39.720 --> 00:47:42.180 William Cheng: Okay. And eventually, when you find the bugs over here, you're going to 354 00:47:43.020 --> 00:47:53.520 William Cheng: Need can experiment on the same a hardware. When you're done over here that you copy your code from, you know, upon the second virtual machine into the first virtual machine and you repo. This is that, and now the bugs are the bugs are fixed. 355 00:47:54.600 --> 00:48:03.090 William Cheng: Okay, so at that time, IBM has competitor. I guess one of the company is called end all and doesn't have the virtual machine technology. So in that case, when there's operating system bug. 356 00:48:03.330 --> 00:48:07.710 William Cheng: And off become very, very difficult to compete against the virtual machine technology now. 357 00:48:08.520 --> 00:48:15.270 William Cheng: Right. Another advantage over here is that we can actually adapt to hardware changes inside hardware. So sorry hardware changes I software. 358 00:48:15.630 --> 00:48:23.040 William Cheng: So, for example, a customer, you know, as IBM to say, hey, you know, we'd like you to add a new machine instruction. Okay. Could you call up your engineering to see how long 359 00:48:24.030 --> 00:48:31.140 William Cheng: How long would it take before it's done right so IBM sales, you know, sales people when I call the IBM engineers, say, you know, the customer wants a new machine structure. 360 00:48:31.410 --> 00:48:35.370 William Cheng: Well, would it be done and the engineers are laughing Right as it may be in two, three years and it will keep 361 00:48:35.880 --> 00:48:39.600 William Cheng: Right, because it's very, very difficult to add a new instruction instead of mainframe computer 362 00:48:39.900 --> 00:48:48.750 William Cheng: Okay, but now with virtual machine monitor the engineers. So you can actually have a in a couple weeks. Right. How would they do that. Yeah. So again, you know, the, the, the full 363 00:48:49.320 --> 00:48:58.860 William Cheng: You know, for the customer. They're running on virtual machines over here. Yeah. So in this case, what we can do is that we can actually add a new machine structure into the existing code. Okay, so here's 364 00:49:00.210 --> 00:49:04.680 William Cheng: Here's a new machine section over here where you actually have this instruction on the real hardware, what's going to happen. 365 00:49:05.340 --> 00:49:15.390 William Cheng: What this is a new machine structure. So, therefore, what you said. Actually this is Russia. It's illegal instruction. So what do we say we're trapped into VMware right so inside VMware, we can actually emulate this instruction. 366 00:49:16.320 --> 00:49:21.330 William Cheng: Okay, when we finish reading this way we can return back to that as they have, you know, that was actually good instruction. 367 00:49:21.540 --> 00:49:31.470 William Cheng: So in this case, we can actually implement implement the functionality inside a Virtual Machine Manager. So this guy is this will be done in a few weeks, or a month, instead of, instead of waiting for two, three years. 368 00:49:31.950 --> 00:49:41.610 William Cheng: Okay, so why is it implement this particular machine. So actually, you know, you actually will tell other customers that hey, we have this new instruction we can patch out the operating system to use this while we're going to give you a new VM M. 369 00:49:42.000 --> 00:49:50.460 William Cheng: So this way you can actually use that if it turns out a lot of people like it IBM can tell they're our engineer, just say hey you know this instruction is really, really popular. Why don't you implement the real hardware. 370 00:49:50.880 --> 00:49:59.430 William Cheng: Okay. Two years later, when the real Hustler comes along, we're going to swap out the real hardware. So in this case we execute this this machine code. Is that a real hardware, it would just work. 371 00:50:00.690 --> 00:50:09.420 William Cheng: OK. So again, you know, if you're if you're the competitor, IBM, you don't have this technology, why not case, you cannot, you know, sort of add new instructions over here, you know, 372 00:50:11.280 --> 00:50:19.560 William Cheng: You, it's very, very difficult for you to adapt to to hardware changes in software. OK. So again, this is a major advantage in using virtual machine. 373 00:50:20.220 --> 00:50:23.820 William Cheng: But you can also use multiple operating system on the same machine, right. 374 00:50:24.390 --> 00:50:34.260 William Cheng: So at the time of IBM, you could run different configuration of the office 360 and then maybe mix them with the CMS often uses them, it'll be very, very flexible. It can be plugged in play. 375 00:50:34.950 --> 00:50:41.010 William Cheng: But as it turns out that you know you know so. So again, you know, in the bill days, you know, the reason the virtual machine. 376 00:50:41.400 --> 00:50:52.500 William Cheng: The virtual machine technology was very popular is because the first two reason but today we have a revival the virtual machine technology and most of the time is because of this reason that we can run multiple operating systems on one machine. 377 00:50:53.070 --> 00:51:01.560 William Cheng: Okay, so these days in the data center. You know what they will do is that they will actually run a different kind of operating system or something that we're on Windows, somewhere around run on Linux. 378 00:51:01.920 --> 00:51:09.420 William Cheng: Because different customer actually sort of required different kinds of some kind of system. Yeah, I mean, the good old days, let's say that you want to run a web browser. 379 00:51:09.900 --> 00:51:18.000 William Cheng: Okay, you wonder what a web browser inside the the internet service provider, what would you do, right. So typically what you would do is that you actually you configure a machine. 380 00:51:18.210 --> 00:51:26.430 William Cheng: And they give you a machine to the internet service provider to say to you install machine into the middle of a network. So this way you know everybody can be easy access to your machine. 381 00:51:27.030 --> 00:51:34.230 William Cheng: Okay, so in that case, you know, once once a web server become very popular and you want to, you know, replace it with a more powerful server. What do you have to do. 382 00:51:34.440 --> 00:51:41.850 William Cheng: Well, you need to you know so configure a bigger server over here and then you go into your internet service providers and say I want to swap the machine out to use another more powerful machine. 383 00:51:42.390 --> 00:51:45.150 William Cheng: Okay, today, you know, we sort of have a completely different. 384 00:51:45.960 --> 00:51:55.200 William Cheng: Different approach using cloud computing were using web hosting, you know, these kind of stuff. So what we're gonna do is we're gonna have to call up our cloud service providers. Hey, could your turn on a 385 00:51:55.530 --> 00:51:57.480 William Cheng: Could you turn on a virtual machine for us. 386 00:51:57.930 --> 00:52:05.940 William Cheng: So inside the code over here we're going to, we're going to have with a big virtual machine, each one of them can run multiple you know Linux machine again Linux virtual machine. 387 00:52:06.210 --> 00:52:14.430 William Cheng: Or windows which machines to all we need to do is to do. For example, we call our Amazon to say, hey, could you turn on a Windows Server. Could you turn on a Linux server for us. 388 00:52:14.610 --> 00:52:23.760 William Cheng: And in this case, we're gonna, you know, give us a shell account. We're going to secure shutting down machine when I set up a web server, and then this guy, we can start taking credit card or something like that and then a month from now if our 389 00:52:24.720 --> 00:52:30.000 William Cheng: If our system is booming. All we have to do is that we call the again we're going to call out VMware again. 390 00:52:30.780 --> 00:52:40.950 William Cheng: So called Microsoft or whatever the you know the call vendor is we can say, Could you turn on more, you know, more virtual machine over here and have all of these virtual machine behave as if there are one virtual machine. 391 00:52:41.310 --> 00:52:47.880 William Cheng: So this way. Again, some of them I run Linux. Some of them I run Windows operating system and this guy i can i just support more customer, I can make money even quicker. 392 00:52:48.750 --> 00:52:54.690 William Cheng: Okay, so again you know this this become the current major reason why we want to use virtual machine in the cloud. 393 00:52:55.170 --> 00:53:06.000 William Cheng: Okay, if he does want to be able to run multiple virtual machines that easily turn them on or off if one day our business go down. All we need to do is to tell them about your turn. Oh, one machine over here. And again, our monthly costs and be lower because we 394 00:53:06.210 --> 00:53:08.280 William Cheng: Were using less resources inside the cloud. 395 00:53:08.850 --> 00:53:16.620 William Cheng: Yeah. So, these days, you know, server consolidation and service isolation become one of the main reason we want to use virtual machine. Okay. We don't need to bring a 396 00:53:16.920 --> 00:53:29.130 William Cheng: Machine into our inner surface water and more. All we need to do is to make a phone call and I'm going to secure shell. You know, so it's into all these machines that we could actually use them. Yeah. Alright. So again, that's that's today's reason 397 00:53:30.510 --> 00:53:40.200 William Cheng: All right, so I guess this is a good point to break. So next time in the third part of lecture 19 we can continue to talk about the other parts of the virtual machine technology. Yeah.