WEBVTT 1 00:00:01.860 --> 00:00:12.960 William Cheng: Oh. Welcome to lecture 11 so now we're one week into Colonel one so kind of one is do in a week. If you have co from previous semester, don't look at them. Don't copy them best to get rid of their 2 00:00:13.290 --> 00:00:19.080 William Cheng: Grading guys, the only war grey. Please read carefully, send me questions. If you're not sure, and 3 00:00:20.160 --> 00:00:27.210 William Cheng: You know, over here, I guess there was a comment to say don't run case you're in a separate process. You'll Keisha is part of you in a process. 4 00:00:28.080 --> 00:00:37.140 William Cheng: The grading guidelines has, you know, Section C and D. So C is for the favorite test. And these were the South contests and the deadlock test. 5 00:00:37.770 --> 00:00:47.340 William Cheng: So the test. There you have to, you know, run them in the foreground and also the printout should be correct. So I cannot tell you what correct print out is supposed to be. 6 00:00:47.910 --> 00:00:57.270 William Cheng: But you should feel free to talk about that in the class Google group used to also see the week six discussion video it's you know it's posted early 7 00:00:57.750 --> 00:01:03.600 William Cheng: So you can, you know, learn how to read the code and try to sort of figure out, you know, what is the printer supposed to be. 8 00:01:04.110 --> 00:01:12.060 William Cheng: And, you know, for the grading guidelines, one of the sections call self checks if you are confused about what to do. 9 00:01:12.540 --> 00:01:18.390 William Cheng: Please send me an email. The most important things that don't assume that you can do, you know, whatever you do, is that'd be fine. 10 00:01:18.930 --> 00:01:26.790 William Cheng: You should check it against the spec and the grading guidelines, they tell you exactly what needs to be done. Okay, so even if after you read that you're still confused. 11 00:01:27.390 --> 00:01:34.140 William Cheng: Feel free to send me email. They after submission and make sure you verify your Colonel submission. The procedure is a little different from warm up. 12 00:01:34.590 --> 00:01:49.530 William Cheng: So one thing is that you should practice to make sure that you get the procedure correctly. I should also do GDP assignment number two. Again, you don't have to turn it in, but you need to be familiar with some of the colonel debugging command, you know, the hopefully that will be useful. 13 00:01:50.880 --> 00:01:59.250 William Cheng: The current one implementation timeline. So again, we're one week into it already. So, till Thursday. This week, you can still keep drivers equal to zero. 14 00:01:59.580 --> 00:02:04.680 William Cheng: And try to get most of their piece, the favor threat has to run with driver equals zero. 15 00:02:05.250 --> 00:02:18.840 William Cheng: So I guess in discussion session I call that phase two, phase one is, you know, don't, don't. Favorite test a tues the past eight of the favor threat test and then afterwards said driver equals one and you need to pass one more, you know, favorite test. 16 00:02:19.800 --> 00:02:28.740 William Cheng: So, so once you said drivers, you go to why you're going to start getting you start getting interrupt so at that point inside you know in a proc run 17 00:02:29.220 --> 00:02:34.830 William Cheng: So this guy. You should be running Keisha again when you first get it to work and should probably should be pretty straightforward. 18 00:02:35.160 --> 00:02:40.920 William Cheng: Even though you might get a bug. Is that your kernel. So, that case doesn't really work, just right, or maybe just stuff. He didn't implement 19 00:02:41.490 --> 00:02:49.500 William Cheng: So the first three command over here, you know, should work. If they don't work, or will you type something in case your problem. You don't see anything ECHO. 20 00:02:50.130 --> 00:02:57.240 William Cheng: What did you do is that you have the source code for a show. So just just single step indication and find out exactly, you know, which statement is not working. 21 00:02:57.930 --> 00:03:02.550 William Cheng: OK, so again you know the code, you never seen it before, but the try to guess what the code is supposed to do. 22 00:03:02.970 --> 00:03:16.350 William Cheng: Guy and then this way you can debug the code again and again. Again, if the code doesn't work. That means that the bug is one of the functions you have implemented. OK. So again, you need to think about what function would call and then maybe you have a bug. 23 00:03:17.820 --> 00:03:23.670 William Cheng: So after that, you need to add three K shell commands want to run each of the sections, C and D test. 24 00:03:24.420 --> 00:03:35.310 William Cheng: So, so in every case shell command, you need to create a child process also get these child processes are the direct child process of the inner process because Keisha is the process that 25 00:03:35.850 --> 00:03:41.220 William Cheng: So you should create a trial process and set the test function as the first procedure of the threat in the process. 26 00:03:42.330 --> 00:03:45.000 William Cheng: Alright, so again if you're confused about this, feel free to send me email. 27 00:03:45.510 --> 00:03:51.990 William Cheng: So again, final. Remember that is a reminder that it's very important that they understand every line of code in favor through a test. 28 00:03:52.410 --> 00:04:00.750 William Cheng: You need to sort of form a mental picture of exactly where all the threats are, how they supposed to, you know, continue to live on how this diet and all that kind of stuff. Okay. 29 00:04:02.550 --> 00:04:08.280 William Cheng: All right, so. So last time we, you know, I sort of finished the first part of 30 00:04:09.660 --> 00:04:14.760 William Cheng: Interrupt because I need to give you everything that you need to know in order for you to kind of why I actually skip 31 00:04:15.630 --> 00:04:22.680 William Cheng: You know, part of the two level model. So we're going to come back to the two level models. First, there's something called a scheduled activation model. 32 00:04:23.310 --> 00:04:29.820 William Cheng: That's the one that we skipped we you know we talked about this slide, there's a problem with a two level model. 33 00:04:30.180 --> 00:04:35.340 William Cheng: One is the IO blocking problem we mentioned that there's, you know, what we have is really not a general solution. 34 00:04:35.580 --> 00:04:43.020 William Cheng: And also, the other one is a priority and version problem, right. The idea here is that, you know, user threat. We're going to have three a priority. So even though you don't do that in 35 00:04:43.890 --> 00:04:48.300 William Cheng: Your one or number two in pieces. There is a way to set up. 36 00:04:48.540 --> 00:04:52.890 William Cheng: You know party so use your thread over here, you can have high priority thread and low priority to threat. 37 00:04:53.070 --> 00:04:59.700 William Cheng: So he's our current over here. The Colonel second also a priority. So one of them over here will be the low party Colonel through and high party Colonel threat. 38 00:05:00.060 --> 00:05:07.320 William Cheng: If it turns out that both of these three companies are the colonel simultaneously. And, you know, as you know, since the user. The user and kernel threat. 39 00:05:07.890 --> 00:05:13.710 William Cheng: There really pass that information about you know which one has higher priority which is low priority, it is possible that, wouldn't this 40 00:05:13.920 --> 00:05:20.010 William Cheng: You know, the high level the hyper to use a threat. When it comes to Colonel, it will use a low, low, low priority current software. 41 00:05:20.220 --> 00:05:25.230 William Cheng: What a low priority current user threat will come into the kernel and then it will use the high party Colonel set 42 00:05:25.530 --> 00:05:37.620 William Cheng: Yeah, so you both simultaneously make a system called into the kernel. Well, guess which one is going to return for us right a high party Colonel third over here is going to be some for us. So in this case, the application program will be very upset you know because 43 00:05:38.430 --> 00:05:49.710 William Cheng: You know, because the application programmer explicitly program that this fish are higher priority than the other one. So, therefore, when you race into the kernel. It should be clear that high priority. So that has to return first 44 00:05:50.610 --> 00:05:54.150 William Cheng: Okay, so this is no as a party version. And this is just one kind of party version. 45 00:05:54.540 --> 00:06:04.350 William Cheng: Later on in the in the semester. We're going to see another version of party virgin problem so often is that party version is pretty complicated even today's if you go to operating system conferences. 46 00:06:04.800 --> 00:06:08.880 William Cheng: People are still trying to solve different versions of party version problem. Yeah. 47 00:06:09.540 --> 00:06:15.420 William Cheng: So what is the solution for that. Right. You know, if you know what, so one solution is that you pass this information to the Colonel. So when the user through 48 00:06:15.630 --> 00:06:23.850 William Cheng: The system going into the kernel somehow the colonel actually find out exactly what they use the third party is remember the user third party can be implemented a piece or a library. 49 00:06:24.360 --> 00:06:28.050 William Cheng: So the colonel doesn't really know about exactly how Peter library implement stuff. 50 00:06:28.710 --> 00:06:33.780 William Cheng: Okay, so therefore it's very difficult for the colonel to figure out. So, so we sort of want a generic way for the Colonel. 51 00:06:34.380 --> 00:06:43.590 William Cheng: To not have this party version problem. Okay, so one of the suggestion over here is that, you know, some some researcher come up with a model called the scheduler activation model. 52 00:06:44.310 --> 00:06:54.360 William Cheng: So the basic solution over here is that the problem the problem that we start over here is that because inside the Colonel. We're scheduling Colonel threat. As it turns out, with schedule will schedule the wrong Colonel threat. 53 00:06:55.050 --> 00:07:01.200 William Cheng: OK, so the solution will be as kind of simple, why don't we just not worried about Colonel threads. Okay, we let the user programs. 54 00:07:01.740 --> 00:07:10.650 William Cheng: We let the user program decide, you know, how, how they should run their threats. Okay, so this way you know the the problem that I just mentioned before it can never happen now. 55 00:07:11.730 --> 00:07:16.050 William Cheng: So the idea of what we hear is that inside the Colonel. I don't want to multiply x, the 56 00:07:17.280 --> 00:07:24.600 William Cheng: You know, okay. So inside corner. I don't want to decide which corner 31st, because if the colonel says around priority weather. In that case, use the application. 57 00:07:25.410 --> 00:07:33.660 William Cheng: Is going to be upset. Okay. So instead what we're going to do is that instead of Colonel, we're going to schedule CPU to processes and not schedule CPUs to Colonel threats. 58 00:07:34.260 --> 00:07:42.540 William Cheng: Okay, so this way when you know if I have three CPUs over here assigned to this process. Then I'm going to give the scheduling decision to the user. 59 00:07:42.930 --> 00:07:51.930 William Cheng: The user space scheduler and the user SpaceX scheduler. They know exactly which still has higher party which has no no party. So in this case, we have three CPU. It was scheduled correctly. 60 00:07:52.410 --> 00:08:04.560 William Cheng: Okay if I have the four CPU, I give the four CPU to another process. So again, this process. You know, when it going to the user space this user space schedule. I can't decide, you know, which has highest priority. So therefore, again, it will not make a mistake. 61 00:08:05.670 --> 00:08:13.890 William Cheng: Okay, so again the solution over here is not to schedule CPU to Colonel threats, but schedule CPUs to use their processes. Okay, so that seems to be 62 00:08:14.430 --> 00:08:23.220 William Cheng: Able to solve the problem is, I'm going to sort of briefly run through an example to see what happens over here. So in this case, we're three CPUs web to user processing. And there are other user processing, of course. 63 00:08:23.760 --> 00:08:29.580 William Cheng: So in process. A over here we have two sets that we have to run here is a high priority. So here's a low party throw 64 00:08:29.880 --> 00:08:35.040 William Cheng: In a scheduler be over here. We also have to user thread. This one is a high party service was low parties that 65 00:08:35.340 --> 00:08:43.710 William Cheng: That. So now when the CPU become available. We need to offer the CPU to the user process. So in this case we do that using something like a call. 66 00:08:43.950 --> 00:08:47.730 William Cheng: Because we're going to make an alcohol into the user scheduler and said, We have a CPU is available. 67 00:08:47.970 --> 00:08:56.610 William Cheng: Do you have anything that you can run. So, of course, if all your threads are waiting, you know, our weddings that kernel or they are you know waiting for new types or something like that. Well, in that case, you'll say, you know, 68 00:08:56.970 --> 00:09:02.610 William Cheng: You say, Thank you very much, but I don't need a CPU that he can pass it on to the next. The next process. 69 00:09:03.690 --> 00:09:12.930 William Cheng: So here's an example when one of the CPU become available. You know, offer it to to the user a Schedule A over here. So scheduler, a over here. There was, they all have to process to threats, I need to run 70 00:09:13.140 --> 00:09:20.250 William Cheng: One of them has higher priority than the other. So therefore, of course, I'm going to get a Sikh of the CPU to the hierarchy. So okay, so this way. 71 00:09:20.610 --> 00:09:25.380 William Cheng: You know, a threat, a one over here will be running on this CPU. And then what about the second CPU over here. 72 00:09:25.530 --> 00:09:33.960 William Cheng: So inside the Colonel, where the second CPU become available. The Colonel has a policy to say that now to see to become available which process to I'd give the CPU to 73 00:09:34.260 --> 00:09:43.920 William Cheng: Do I give it to the process as I give the process speed up the process. See, so again inside the Colonel, they need to make the scheduling decision to to schedule schedule CPU on 74 00:09:44.190 --> 00:09:53.430 William Cheng: The right or to, to, to give CPUs two processes that. So in our example over here. The second CPU when it becomes available. As it turns out, that will now we have to offer the CPU. 75 00:09:53.760 --> 00:10:02.310 William Cheng: The process be so therefore we're going to send it to schedule it be over here the schedule up. He says, I have to says I have to round one is higher priority than was low parties. So clearly, I'm going to run this. 76 00:10:02.520 --> 00:10:17.100 William Cheng: You know, I'm going to use a CPU to run a high priority threat there. And then the third CPU overhead become available. So again, I'm going to look at the colonel scheduling policy to say which process will offer the CPU to. So in this example, for some reason, I still offer back to 77 00:10:18.390 --> 00:10:22.530 William Cheng: Back to process. Me and process me says, oh, I have a lower Party said I can run this. 78 00:10:23.610 --> 00:10:27.840 William Cheng: I can run on CPU, so therefore they will say thank you very much and it will take the the CPU here. 79 00:10:28.590 --> 00:10:32.790 William Cheng: So now they're all running right so so whatever when one of them make a system call 80 00:10:33.210 --> 00:10:34.920 William Cheng: Okay, so, so let's take an example of 81 00:10:35.250 --> 00:10:40.230 William Cheng: A one over here right before we started the two level model when you make a system called sometimes going to get into trouble. 82 00:10:40.380 --> 00:10:49.380 William Cheng: So now what a winemaker system Colada right so system called here it comes inside the colonel and not to become a colonel threat. So in this example here is going to go through, through some IO. 83 00:10:49.650 --> 00:10:59.940 William Cheng: Get when it goes down my. Oh, then what it would do is enable ad itself to the IQ and then it going to cost us switch to give up the CPU when they call. So let's switch to give you about a CPU. Now the CPU become available. 84 00:11:00.540 --> 00:11:04.710 William Cheng: Right, so it again where the CPP funk become available. We're going to look at the the colonel scheduling. 85 00:11:05.340 --> 00:11:12.300 William Cheng: You know policy over here and decide who to offer it to. So again, we offer the CPU to processes and not threats. Right. So in this case, 86 00:11:12.510 --> 00:11:22.020 William Cheng: You know, maybe we can offer to to to to to process C or something like that, or we're going to offer it back to process a. So in this case we offer to process a over here process. Oh, I have another part 87 00:11:22.410 --> 00:11:29.610 William Cheng: Another thread I can run because one of the setup here is inside a colonel, so therefore I can run the other thread. So again, I will take the CPU, I will start running this 88 00:11:30.690 --> 00:11:36.810 William Cheng: OK. So again, we don't have to do what the truth that we saw in the last lecture, you know, block on the Center for using a sort of a 89 00:11:38.610 --> 00:11:46.260 William Cheng: Non blocking system call and that's a little too much guys over here simply want to see to become available, then you know the user space scheduled. I can't decide, you know, 90 00:11:46.530 --> 00:11:56.400 William Cheng: That the weather has said to run. So in this case, you can actually use all the CPU z. So you've all the CPUs offer back to process a process that has many other threats. They can run. They can run in parallel. 91 00:11:57.720 --> 00:12:07.800 William Cheng: Guys will get this solves the problem of, you know, I, oh, blocking in the two level model. Well, I said. So this one was that running over here. So let's say that in a second CPU over here, you know, 92 00:12:08.490 --> 00:12:16.680 William Cheng: The sweat be one over here is a CPU hog. Okay. So to use the CPU, it doesn't it doesn't give up. Okay, so at some point over here. 93 00:12:16.980 --> 00:12:26.730 William Cheng: So, so again, when this is running out of CPU. We're going to start a timer. So in this case, the timeless for this particular CPU. If this way, it doesn't give up the CPU and the timer goes off, what's going to happen. 94 00:12:27.060 --> 00:12:35.100 William Cheng: We're going to try inside the CPU. Well, we try these out of CPU over here, this thread is not running anymore because their CPU over here. Go service the interrupt service routine. 95 00:12:35.700 --> 00:12:47.040 William Cheng: Okay, when a service enter our services team, they decided this trip us up too much of the time slides. So what it will do is that is that that he will. He will keep the stress suspended and now the CPU become available. And they can offer the CPU to somebody else. 96 00:12:48.210 --> 00:13:01.710 William Cheng: Okay. So, using this particular approach we avoid the you know the the the party version problem. And also we we we also we have what the I O CLOCK AND problem. Okay, so this seems to be a pretty good solution that 97 00:13:03.240 --> 00:13:11.340 William Cheng: Schedule activation model seems like a good solution for the two level models, but it hasn't been adopted by any major operating system vendor. So why is that 98 00:13:11.880 --> 00:13:16.920 William Cheng: Okay, because you know it can take many, many years to take something in research, right. So, so 99 00:13:17.160 --> 00:13:26.760 William Cheng: You know, this particular model was proposing research. So some people, you know, implemented some kind of a toy and this is them trying to demonstrate that this works, but we don't really know how well it works in the real in the real world. 100 00:13:27.060 --> 00:13:36.120 William Cheng: Okay, and he takes many, many years for people to experiment on it. So what they need to conduct, you know, extensively experiment to know about all the pluses and minuses of this particular approach. 101 00:13:36.600 --> 00:13:39.180 William Cheng: Okay. And also, you know, this would be your approach. 102 00:13:39.540 --> 00:13:49.650 William Cheng: may only resolve this party virgin problem. What about all the other party virgin, Baba. And so maybe we need a different kind of scheduler so that we can actually, you know, avoid all the other party version problem. 103 00:13:50.040 --> 00:13:53.760 William Cheng: Guys, or maybe maybe one of one of these days. We're going to see Linux, sort of, you know, 104 00:13:54.870 --> 00:13:58.080 William Cheng: Episodes or or pick this approach to be added. 105 00:13:58.770 --> 00:14:05.520 William Cheng: To the cinema to schedule to to level threat or maybe Linux, we just stay at one level model forever. Right. So. So again, we don't know. 106 00:14:05.790 --> 00:14:21.180 William Cheng: Yeah so. So the important. The idea here is that you know when something come out of research, even if it looks very, very good. It will take you know oftentimes can take more than 10 years or 15 years before eventually, you know, some some commercial company will will pick it up. Yeah. 107 00:14:22.470 --> 00:14:26.280 William Cheng: Alright, so that's the schedule activation model. So now we're going to continue with interrupt. 108 00:14:26.610 --> 00:14:33.450 William Cheng: Last time we finished talking about the interrupt handling. Right. And also we give you the code that you can use for your current one. And I'm going to move on. 109 00:14:34.110 --> 00:14:39.210 William Cheng: We're going to have two things we need to talk about what it's called before work and the other one's called deeper director processing. 110 00:14:39.930 --> 00:14:49.710 William Cheng: So default work over. Yes. What did before work right we mentioned before inside interrupt service routine, we need to do as little as possible at the two things that we have to do is to unblock a colonel threat. 111 00:14:49.920 --> 00:15:00.600 William Cheng: And start the next IO operation. Okay. Everything else can be done at a later time. Okay, so there's no as default work. You want to defer the work of the interrupt service routine and you need to do it at a different time. 112 00:15:01.470 --> 00:15:06.420 William Cheng: Okay, so the question is, how should you do and what is the right time to do it. OK. So the basic idea here is that 113 00:15:06.930 --> 00:15:11.070 William Cheng: Since these are the coatings that interrupt service routine and there are pretty important, right, because you know 114 00:15:11.370 --> 00:15:19.770 William Cheng: The, you know, I was gonna come one after another. If you know finished doing the work right now. And later on, when I know you know Rob calm while the name, then it's possible to get into trouble. 115 00:15:20.100 --> 00:15:31.620 William Cheng: Okay, so therefore the interrupt service routine is pretty important. But we also mentioned that you know that the the once you get into the inner contacts you don't get back to the threat contacts until you completely done with the internal contacts. 116 00:15:32.040 --> 00:15:38.400 William Cheng: Okay, so that's how we can really spend too much time in enroll contacts we need to sort of go back to the contacts as soon as possible. 117 00:15:38.640 --> 00:15:47.460 William Cheng: Okay, so these two things, these two forces sort of going against each other. So the question is when is the right time to do all these work. They are not as important as the absolute 118 00:15:47.760 --> 00:15:54.930 William Cheng: You know, important things that are you know in our social team, but, you know, maybe they're a little more important than the work inside the inside of my contacts. 119 00:15:55.470 --> 00:16:01.020 William Cheng: Guys are going to sort of see, you know, different operating system and what actually take different approach to implement these d forward. 120 00:16:01.680 --> 00:16:05.160 William Cheng: Okay, so one of the, you know, what is it a common example with the full word is 121 00:16:05.760 --> 00:16:15.750 William Cheng: Never interrupt. So for example, this is your network interface card. The new interface card. You're getting a lot of data from the internet. For example, you could download Ubuntu 16.04 lots of data is going to come in. 122 00:16:16.170 --> 00:16:23.910 William Cheng: So they're going to fill the network interface card buffer with a lot of data. So what you will do is that a new interface card over here will be set out to TMA the data. 123 00:16:24.150 --> 00:16:28.920 William Cheng: into memory and when they finished transferring a lot of data into memory. What it will do is it'll generate it you know up 124 00:16:29.460 --> 00:16:36.150 William Cheng: Okay, so instead of, you know, observers hootie we need to deal with all this data that just copying the memory. Okay, there's a lot of data. 125 00:16:36.510 --> 00:16:43.380 William Cheng: Right. So, therefore, again, what we have to do is I'm walking closer started next hour operation. What are the other work that we should do instead erupts diversity. 126 00:16:44.130 --> 00:16:52.950 William Cheng: That. So you probably heard of something called TCP IP right so now looking over years TCP IP TCP IP is actually layer. There's one layer called TCP and there's another layer. 127 00:16:53.490 --> 00:16:57.180 William Cheng: So there's one local IP and then there's another layer called TCP over here. 128 00:16:57.540 --> 00:17:08.550 William Cheng: So it actually is the data needs to be passed around inside the kernel go through multiple layer and we need to parse the, you know, so part of parse the data that come into memory. I mean, you have done parsley did already warm up one and two. 129 00:17:08.880 --> 00:17:14.370 William Cheng: I mean, that can take time. Okay, so again, all these things going to take time. So, so, so, you know, so, so in this case it will take 130 00:17:15.210 --> 00:17:29.310 William Cheng: You if you do this instead of interrupt service routine, then that will be the wrong time to do it. Okay, so the question is, how do you differ this work to some other time. You know, and then and then the other question is who's actually going to work on the deeper work. Yeah. 131 00:17:31.380 --> 00:17:41.100 William Cheng: Alright, so one of the solution over here is that we can sort of consider that the default work, they are less important than all the interrupt service routine, but they are more important than all the threat work. 132 00:17:42.090 --> 00:17:45.420 William Cheng: Okay, so, so therefore, one, one possible way to do this is that 133 00:17:45.900 --> 00:17:54.750 William Cheng: You know, he said, you know, he said, you know, I've handler when you're when you're about to finish all the interrupt service routine. That's when you that you know that's what you supposed to handle to do for work. 134 00:17:55.290 --> 00:18:03.600 William Cheng: Okay, so let's take a look at example of what this will car. So remember, the, the, you know, observers routine. There's a top level interrupt handler. And then there's the interrupt specific interrupt handler. 135 00:18:03.990 --> 00:18:09.600 William Cheng: So over here, there's some pseudo code that looks like this. This is a problem when you interrupt handler right when you get out of the 136 00:18:10.620 --> 00:18:18.900 William Cheng: Way you get out there of how abstraction layer, then in that case, you're going to be handling interrupt service routine. So in this case, this will be the function that you call. So in this case, this 137 00:18:19.680 --> 00:18:25.080 William Cheng: This one is interrupted by this particular device. And again, that device has a major device number and a minor device number 138 00:18:25.290 --> 00:18:32.580 William Cheng: By looking at a major device number, you know, which device driver that will handle you also know what is the interrupt previous level for that particular device. 139 00:18:32.880 --> 00:18:35.460 William Cheng: Okay, so therefore we're going to use a shorthand notation over here to say 140 00:18:35.670 --> 00:18:44.490 William Cheng: This is called the inner vector. It's an array of function pointer index on the device number again the major device number over here. And then we're going to call our in our social team like this. 141 00:18:45.000 --> 00:18:47.550 William Cheng: Okay, so get one on a pseudo code over here. This is how we 142 00:18:48.090 --> 00:18:55.230 William Cheng: How we invoke the, you know, our servers routine how we set the IPL to the right level and then we're executing code inside this interrupt service routine. 143 00:18:55.530 --> 00:19:04.500 William Cheng: Then again, we do that. The important thing we on Bond Colonel where we started, next, the next, the next, I'll operation, anything that needs to be the four, we're going to add it to a work cute. 144 00:19:05.730 --> 00:19:11.580 William Cheng: Okay, so, so, so, so again the future will look like this. Right. So right now. So this example over here. We're going to throw up a colonel threat. 145 00:19:11.910 --> 00:19:18.270 William Cheng: And we saw before. When you you know have a colonel. So what does the colonel stack look like right the Kronos not going to bottom. The Colonel stags, the user select contacts. 146 00:19:18.480 --> 00:19:27.780 William Cheng: And the colonel stressed out for him is like this and the top of the Colonel's crimson and go go like crazy because you're making see function call and all of a sudden we get a hallway interrupt and they were excellent. All right here. 147 00:19:28.380 --> 00:19:38.580 William Cheng: We go. So when we remember what we said before is that we're going to say the colonel colonel. The Colonel fit contest right at the top of the stuck over here. And then we're going to build a stack rank to execute this code. 148 00:19:39.960 --> 00:19:44.370 William Cheng: Okay, so let's say that we are executing some kind of a keyboard handlers. So this is really low priority. 149 00:19:44.700 --> 00:19:54.540 William Cheng: The low party IPO. So this one IP or number number over here as serious as three is pretty low. So in this case, we're handling the sort of the keyboard interrupt. So again, the top of the stack of years. 150 00:19:54.960 --> 00:20:02.430 William Cheng: Down like crazy because we're going to make some see function call India we finished the important stuff right the important stuff on blog, Colonel. Sure. I started. Next I operation. 151 00:20:02.640 --> 00:20:07.770 William Cheng: And now we're going to do that. We're going to take all that the forward we're going to simply and cure to work, you 152 00:20:08.880 --> 00:20:16.440 William Cheng: Guys over here, when we're writing one line of pseudo code that we're going to call the en que function we're going to include more work over here on to the work you 153 00:20:16.830 --> 00:20:23.580 William Cheng: Guys are working over here just data structure is not a colonel. So we're going to add a function pointer over here, you know, the phone tomorrow, get into the 154 00:20:24.570 --> 00:20:29.580 William Cheng: Into this cute. Okay, so what is this function partner is going to get the get the Q, we're going to teach you that in a later time. 155 00:20:30.390 --> 00:20:33.450 William Cheng: That. And also remember that once we're in the, you know, October so team. 156 00:20:33.720 --> 00:20:46.440 William Cheng: You know. So in this example, we're into our level number three over here. So at this point, IPL is going to be equal to three. Right. So we're blocking in a rough on level 023 and we unblocking or off and for all the way to, you know, 31 157 00:20:46.800 --> 00:20:52.380 William Cheng: Okay, so now a more urgent y'all can happen. So when the on the more or do you know when it happens, which happen. 158 00:20:52.800 --> 00:21:01.620 William Cheng: Right. So again, we're gonna say the context of the interrupt service routine at the top of the colonel stack over here. And then we're going to build a cycling over here to execute this code for the more urgent interrupt. 159 00:21:02.430 --> 00:21:09.030 William Cheng: Okay, so in this example over here, the more urgent here. Rob is a disc interact with a general level seven so that device over here is going to be able to serve in 160 00:21:09.240 --> 00:21:11.430 William Cheng: And then I'll be here. Would it be used to interrupt service routine. 161 00:21:11.640 --> 00:21:19.860 William Cheng: And here's the thing, you know. Absolutely. I'll be here with IP or equal to seven. Right. So again it do the important things at the end over here, what he would do is that it will add 162 00:21:20.040 --> 00:21:30.150 William Cheng: Its own version of the more work, the work you so now the work you start building up with more and more work that needs to be done once you're done with the internal contacts that are so in this example here. Where's the 163 00:21:31.230 --> 00:21:39.510 William Cheng: Cut over here and now, again, since it is equal to seven or we're blocking off on level 027 and interim level eight through 31 or so. 164 00:21:40.110 --> 00:21:43.800 William Cheng: We can get a more urgent interrupt so maybe the next one over here is going to be the know interrupt. 165 00:21:44.070 --> 00:21:52.950 William Cheng: And that way you know obviously level 23 over here. We're going to save the context of the disc interrupt right here. We build a stipend for them. Well, you know, up and the device number over here you go to 23 166 00:21:53.190 --> 00:22:00.990 William Cheng: Again, in this example is equal to IPO level 23 so we're going to call the interrupt service routine for level 23 and this is the interrupt service routine. 167 00:22:01.200 --> 00:22:06.690 William Cheng: We're going to unblock the colonel fell going to start a next I operation. And then all that before work over here, we're going to add it to the work you 168 00:22:08.070 --> 00:22:12.690 William Cheng: Also can see that, you know, every you know of service with him, can all our work to the work you. So when do you get to work on it. 169 00:22:13.080 --> 00:22:23.400 William Cheng: Okay. All right. So, you know, I'm number 23 is over here. Eventually, you know, there's, you know, servers are doing. Again, they can interrupt by another you know 27 or 29 or something like that. So eventually, you know up number 23 will finish. 170 00:22:24.000 --> 00:22:27.750 William Cheng: Okay, well you know I'm number 323 finish, then it will return from this function right 171 00:22:27.960 --> 00:22:34.740 William Cheng: Then take a look at what the code will do over here. It says if the previous contest equal to three contacts, right. So I'm going to move on to the next instruction over here. 172 00:22:35.010 --> 00:22:45.060 William Cheng: He is pointing right here, over here, so, so, so in this case the staff room over here for interrupt number 23 but I get completely part because this function is going to return. So now, once I actually get a call like this. 173 00:22:45.660 --> 00:22:51.240 William Cheng: Okay, so what we can do that. We can look at the previous contact to see if the previous contacts is a threat contacts. 174 00:22:51.630 --> 00:23:02.430 William Cheng: Because how do we do that right, we have the start point it will be appointed the top of stuck over here, we can peek down the start point over here to see, you know, see the previous contacts over here. So this is the context for interrupt number seven. 175 00:23:03.330 --> 00:23:08.610 William Cheng: Okay, so can the colonel know whether this contact belong to the you know observers of you don't belong to the contacts. 176 00:23:09.360 --> 00:23:12.720 William Cheng: Well, of course the colonel can do that because the cursor is the most powerful thing in the world. 177 00:23:12.930 --> 00:23:21.060 William Cheng: Right. So, therefore, what it will do is it will make sure that when it push you know push this information onto the stack, he will leave in enough hands on it so they can tell whether 178 00:23:21.270 --> 00:23:26.190 William Cheng: You know, when we return. We'll return to it, you know, a contest or return to our contacts. 179 00:23:26.640 --> 00:23:32.100 William Cheng: Okay, if you return to a three contacts there. What we're going to do is that we're going to work on all the different work. 180 00:23:32.640 --> 00:23:37.530 William Cheng: Okay, otherwise. So this example over here, the previous contacts in our contacts and this is where we turn for this function. 181 00:23:37.800 --> 00:23:41.490 William Cheng: When we return from this function, then we're going to go back to the interim number seven contacts. 182 00:23:41.610 --> 00:23:49.230 William Cheng: So this stuff will be removed over here. And then we're going to go back to interrupt number seven. So it will look like this. Right. We're still in the middle of interim number seven right here. 183 00:23:49.410 --> 00:23:53.250 William Cheng: The top of the stack over here. So don't go crazy because it's making see function call. 184 00:23:53.580 --> 00:24:04.590 William Cheng: Yeah. So yeah, we can get in order. Again, or we can eventually finished interrupt service with the numbers. However, when it finishes, we're going to return from this function and this document will get pop and then it will look like this. 185 00:24:05.310 --> 00:24:14.370 William Cheng: There so that we can check the previous content equal to three contacts. So in this case, when we look at the previous context, you know, which is instead of stock room right here. It's going to be the interrupt. 186 00:24:14.760 --> 00:24:24.570 William Cheng: In one number three is a handler contacts, so we know that it's a lot of contacts. So again, I'm going to skip all this code return over here as soon as we return over here. We're going to back into either off on number three. 187 00:24:25.260 --> 00:24:35.550 William Cheng: Guys, and then we'll look like this. Again, right. We're in interrupt number three over here again the top of the segments go up and down like crazy, but eventually we can get interrupted by a hot more important you know up well. 188 00:24:35.820 --> 00:24:42.510 William Cheng: Eventually you know of numbers, we will finish that. So when it finishes over here, this stock rooms are God. And then we're going to go to the next instructions over here. 189 00:24:42.720 --> 00:24:50.610 William Cheng: And it's the previous content equal to three contacts. So now we can see that if we return from here, then the previous contact is going to be the colonel threat contacts. 190 00:24:51.540 --> 00:25:00.150 William Cheng: Right. So now we know that we are done with all the interrupt service routine, except for the default works now good work on a different word. So here's how you supposed to work on the forward. 191 00:25:00.570 --> 00:25:05.250 William Cheng: Read the first thing that you do is that you are mass to interrupt. Why do you amass they interrupt. 192 00:25:05.820 --> 00:25:13.620 William Cheng: Okay, so even though we're assuming that you know social team, but right IP is equal to seven. So sorry IP. I go to see over here. In this example, we're in the middle of the keyboard interrupt. 193 00:25:13.890 --> 00:25:20.340 William Cheng: Right, but we need to amass either up because the work that we're working right now they're all less important than any of the interrupt service routine. 194 00:25:21.750 --> 00:25:32.970 William Cheng: OK. So again, there are more important than all the third word, but they're less important than interrupt service routine. So, therefore, you have to enable you know up. So now when when when Holly, what happens over here, then we can actually will go go go to Iraq service. Okay. 195 00:25:33.990 --> 00:25:41.910 William Cheng: So then I must say, you know, up over here. So now I feel it's going to go to zero. So, this call, we will execute with IP r equals zero over here. 196 00:25:42.210 --> 00:25:50.790 William Cheng: Okay, so then we're kind of in a strange context we're really not in their contacts, because we're still in the interim, I mean, we were still at the pub level interrupt handler over here. 197 00:25:51.090 --> 00:25:57.570 William Cheng: Okay, but again we're looking. We're not really inside of our contacts, but we said IPI equal to zero, which is equivalent to the three contacts. 198 00:25:58.500 --> 00:26:05.430 William Cheng: Or guys what again all these things, you know, all these contracts are just abstraction. It's okay to actually be violent, all these rules, okay. As long as you know what you're doing that. 199 00:26:05.730 --> 00:26:13.710 William Cheng: I saw you know whatever it is that it will go go take a look at the work you if the work is not empty. So we're going to go through the work to DQ a function pointer over here and I'm going to call it. 200 00:26:14.310 --> 00:26:19.440 William Cheng: Okay, so that's how you're going to work on all the different work by going to keep doing this until the work he was empty. 201 00:26:20.490 --> 00:26:23.130 William Cheng: That. So, by the way, this call look familiar to you. 202 00:26:23.640 --> 00:26:34.200 William Cheng: It should be. This is, you know, like your server 30 warm up to. That's what it does, right, I mean, you know, as long as the tutor is not empty, he will keep the queuing Pakistan to two and then it will work on it and transmitting them. 203 00:26:34.980 --> 00:26:42.180 William Cheng: Okay, so we will see the sort of the same you know co pattern over and over again. Yeah. Alright, so this is how you have a deeper work. 204 00:26:45.390 --> 00:26:55.770 William Cheng: Okay so different operating system actually take a different approach windows, you know, this is the windows, you know, interrupt party level and we mentioned before, you know, in the good old windows architecture. They have 32 205 00:26:56.310 --> 00:27:07.680 William Cheng: Different level go from zero to 31 as it turns out, level 012 or they offer software interrupt. OK. So again, specifically zero is for the third contacts and then, you know, 206 00:27:08.640 --> 00:27:15.600 William Cheng: There's something called a PC, which we're going to look at it. Pretty soon. And then there's DPC these VC stand for the for procedure call 207 00:27:16.080 --> 00:27:21.690 William Cheng: Okay, so they actually they handle all the interrupt at interval level number two. Okay, does that make sense. 208 00:27:22.470 --> 00:27:31.890 William Cheng: That actually makes perfect sense because you know in our global number to over here. It's less important than all the other hardware interrupt because all the hallway era. They are a higher interrupt privilege level. 209 00:27:32.850 --> 00:27:39.270 William Cheng: Okay. And also this, you know, global here is more important than the contacts, because the IP out over here. He's bigger than zero. 210 00:27:40.620 --> 00:27:50.010 William Cheng: Okay, so the windows philosophy sort of matches what we're doing over here to say all the deeper work. They're less important than the highway, you know, handling and they are more important than my contacts there. 211 00:27:51.390 --> 00:28:02.340 William Cheng: So you can also see that yeah let's go over some of these your IP Ohio vehicle to 31 and I, and then I feel over 30 as power failure. So that's where you lose power is that the most urgent interrupt. 212 00:28:02.610 --> 00:28:09.060 William Cheng: Well, yeah. Right. Well, you lose power over here, you need to save all your work as much as possible. You know, before before the part gets lower and lower. 213 00:28:09.450 --> 00:28:14.970 William Cheng: Power gets lower and lower, that this is going to start spinning slower and slower. Well, then the end to end up with this crash. 214 00:28:15.630 --> 00:28:23.250 William Cheng: Okay, so therefore, when you get a part of a power failure interrupt. The most important thing is that you need to make sure that the disk is going to stop spinning as soon as possible. 215 00:28:23.730 --> 00:28:29.670 William Cheng: Okay, what are you going to make sure that you know that this not that this is not is not going to hurt your operating system that 216 00:28:30.720 --> 00:28:39.480 William Cheng: You know I'm number 29 OBS the entire process or interact. We don't know what they are yet they don't want to see what they are, you know, have number 28 over here, this is the timer interrupt. 217 00:28:40.140 --> 00:28:46.950 William Cheng: Okay, so when you have preempted scheduler. We're going to use a timer. We have alarm clock. We have a timer so yeah hi Marina Rob is very, very important. 218 00:28:47.220 --> 00:28:57.060 William Cheng: So, so therefore, they're very high high level. Yeah. And then the other one over here, right, there's that there's a network and network interface card that this controller. There's a keyboard and all that kind of stuff. 219 00:28:58.260 --> 00:29:12.600 William Cheng: Is a window. This is what you do it right. So instead of, you know, observers will do over here. If we want to add the Fort Worth, all we need to do is that an intro level. Number two, there's a queue called the TPC. Q Okay TPC I guess that differ, you know, this is a fee for processing. 220 00:29:13.980 --> 00:29:26.880 William Cheng: What is called differ differ procedure call. Yeah. Okay. So there's a Cuellar there. So what do we do is that, is that a euro handler, you do the importance of applause Carlos. So the next hour operation and then you add more work to the DP CQ. 221 00:29:28.050 --> 00:29:37.620 William Cheng: There's a, there's a, there's a queue that exclusively used by the, by erupts servers three number two. Okay. And then what you will do is that you would generate a software interrupt. 222 00:29:38.520 --> 00:29:41.310 William Cheng: Okay, so this one will you generally software, you know what's going to happen, right. 223 00:29:41.400 --> 00:29:49.500 William Cheng: So since over here I'm handling a higher rate or up all the horror interrupt level is bigger than or equal to three. So, therefore, this time IPL is going to be greater than equal to three. 224 00:29:49.650 --> 00:29:54.300 William Cheng: So therefore, if you generate you know number to over here in revenue. Number two is going to become pending. 225 00:29:54.810 --> 00:30:00.840 William Cheng: So you continue to do whatever you're doing before. So you get to finish this stuff. Eventually when all the hallway in rubber done 226 00:30:01.440 --> 00:30:09.720 William Cheng: Okay, so, so we brought all the interrupt then then then all the hallway interrupt eventually interrupt number two. I'll get deliver the here's the service routine for 227 00:30:10.050 --> 00:30:19.800 William Cheng: Number two, what he would do is that he will go to the TPC Q over here as the CVS empty if they're not MP there with the acute the function pointer and then call the function ponder to work on the default work. 228 00:30:21.030 --> 00:30:28.290 William Cheng: Okay, so you know way windows actually does this very, very cleanly by you by sitting in around level. Number two, how to handle DPC work that 229 00:30:31.200 --> 00:30:42.060 William Cheng: Linux has a different approach. So Lynn has different philosophy. So they believe that the for work is just as important as Colonel threat. So what they will do is it will actually designate a colonel threat to handle all the default work. 230 00:30:42.450 --> 00:30:52.410 William Cheng: Right. So this case. Instead, the interrupt service routine over here, what you will have to do is that you need to add more work to the work you and then in this case, you know, since the, you know, 231 00:30:54.210 --> 00:31:00.000 William Cheng: This is the default work threat. Again, that's a certain sort of Colonel that's that might be sleepy. So in this case you need to wake it up. 232 00:31:00.690 --> 00:31:10.650 William Cheng: Okay, so I'll be here the quarter VSS set eval. What does any bad, right. Remember event notification condition variable. They're all the same thing. So this one is peace rare condition signal. 233 00:31:11.640 --> 00:31:17.670 William Cheng: Okay, so today, you know, he's not a colonel, we should signal condition. All you do is that you pick up a threat and you move into a rank you 234 00:31:17.970 --> 00:31:25.740 William Cheng: Guys over here. This is how we wake up you know the other. The Colonel said that's that's handling all the different processing. So here's the code for the 235 00:31:25.920 --> 00:31:34.410 William Cheng: The Colonel threat. So over here, it's called the software interrupts or so again this is really not sorry interrupt it just a kernel thread that handle the different processing. 236 00:31:34.800 --> 00:31:42.150 William Cheng: Okay. So this guy is. What is it called look like, right, it goes into a little bit cough syrup away event way for you bad. How do you know what is wait for a bad 237 00:31:42.510 --> 00:31:47.490 William Cheng: Right that piece of a condition where. But again, this is the kernel version of Peter condition way it's going to sleep on a 238 00:31:47.790 --> 00:31:51.960 William Cheng: Asleep on cue. I'll be here waiting to be woken up by any of the interrupt service routine. 239 00:31:52.170 --> 00:32:00.810 William Cheng: When he wakes up, he will check the work you to see if it's empty. If it's not empty, it will keep working on all the different work until the work is empty and when they're done it. Go back to sleep again. 240 00:32:01.740 --> 00:32:07.170 William Cheng: That. So what is this called remind you of rice. The discussion remind you of the control see catching threat. 241 00:32:07.560 --> 00:32:13.890 William Cheng: Or your control. So you can you throw the cold look exactly like this except. Is that a way for you bet you called segue. You wait for a signal. 242 00:32:14.490 --> 00:32:22.350 William Cheng: That is, again, this is why I get us where people think signal or software you know Rob excuse over here with yourself interrupt and I just said that this code look just like the signal handler, while 243 00:32:22.740 --> 00:32:28.830 William Cheng: Not the signal handler, like a signal catching threat. So again, you know, you can understand the white people confuse those two terms. 244 00:32:31.170 --> 00:32:38.190 William Cheng: Alright, the next thing we're going to take a look at is that, you know, as it turns out that you have to implement for preemption. You can also use it for processing. 245 00:32:38.520 --> 00:32:50.100 William Cheng: Oh, yes. Oh, God, what is to have preemption right you're running a thread inside the Colonel, all of a sudden you're running a different thread inside of Colonel, so we're going to say that the second threat preempted. The first threat. Okay, the, sorry. 246 00:32:50.760 --> 00:32:58.440 William Cheng: You saw running out of CPU and then all of a sudden you run a different settings out of CPU. So the second set basically kick out the first graph on the CPU so 247 00:32:59.070 --> 00:33:06.180 William Cheng: That's called preemption right so we're gonna take a look at. So I mean, we've been will be using that term, we said, oh, you have an aquarium. The Colonel will grab the Colonel. 248 00:33:06.690 --> 00:33:13.530 William Cheng: So now we're actually going to see exactly how do you implement preemption yet, but we're going to take a look. Look at two different cases. 249 00:33:13.950 --> 00:33:18.150 William Cheng: One is that if you have a pre pre NT kernel like like the wind is going over here. 250 00:33:18.690 --> 00:33:24.450 William Cheng: So in this case, the only thing that you can preempt that you can pre AMP, a user threat. Okay, you can always pre AMP, a user to 251 00:33:24.870 --> 00:33:30.330 William Cheng: The colonel. So whether you can preempt it or not depends on whether you are you're you're implementing a preemptive Colonel 252 00:33:30.810 --> 00:33:37.800 William Cheng: Colonel. Yeah. So the first kind of preemption over here for user level knee and then we can sort of think about this is the case for the non preempted, Colonel. OK. So again, 253 00:33:38.010 --> 00:33:45.690 William Cheng: The definition of a non planner kernels. If you're running a colonel where you can get switched to the Iraq contest, but will you come back you come back to exactly the same threat. 254 00:33:46.530 --> 00:33:51.840 William Cheng: Okay. So in this case, you know, your current also cannot be preempted. So in this case, you can still present to the user threat. 255 00:33:52.260 --> 00:33:57.840 William Cheng: Okay, so, so how do you do that, right. So again, this case, you know, when the user threat, get on the CPU went away. Now a 256 00:33:58.260 --> 00:34:09.420 William Cheng: Well, why not have an alarm clock when the alarm clock goes off, we're going to get an alarm clock interrupt service routine. So here is the alarm clock interrupt service routine. Right. So again, we're going to unblock a camera flash started. Next I operation. 257 00:34:09.630 --> 00:34:13.440 William Cheng: And then we're going to check whether the current threat us up too much of the CPU. 258 00:34:13.980 --> 00:34:26.670 William Cheng: Okay, I'm going to call the function over here to say if the time slices over for the current where if it's yes all we need to do is to set a global variable to say that when we return back into the user through our contacts we should give the CPU to a different threat. 259 00:34:28.110 --> 00:34:36.720 William Cheng: So, so this is a global variable over here to say that, you know, to say that when we return back into the users, the user space, we need to switch give the CPU to somebody else. Okay. 260 00:34:37.260 --> 00:34:45.450 William Cheng: Alright so this coast, you know, the example that we saw before. We are going to sort of enhance it a little bit. We still have the top level interrupt handler over here. We're going to handle interrupt specific 261 00:34:46.110 --> 00:34:53.610 William Cheng: You know, sort of a device specific handler. And then what we do is that, you know, we were doing the footwork right so now we're going to perform an extra check over here. 262 00:34:53.790 --> 00:35:00.540 William Cheng: We're going to see if the previous mode over here at the bottom of the Colonel's that are we going to return back into the user mode or we're going to return back into the kernel mode. 263 00:35:01.620 --> 00:35:05.130 William Cheng: Okay, if we're going to return back to the kernel mode, then we don't execute these extra call 264 00:35:05.340 --> 00:35:12.540 William Cheng: But if we're going to return back into the user mode. That means that we're at the bottom of the colonel stuck over here. So if we return over you're going to end up returning to the user space. 265 00:35:13.380 --> 00:35:19.560 William Cheng: Okay. So this guy is what we'll do that we'll check the global web over here to see. Should we give out the CPU to somebody else. 266 00:35:19.830 --> 00:35:28.650 William Cheng: If we should then we call this function should call reschedule. Okay, what does research schedule reschedule is simply add yourself to the wrong queue and then cause stress switch to give up the CPU. 267 00:35:29.040 --> 00:35:39.420 William Cheng: That we saw before. This is function called yield. Right. There's one called y el de call you is to give up the CPU so reschedule the same thing. We're going to add yourself to the run queue. And then we're gonna call threat switch to give up CPU. 268 00:35:40.260 --> 00:35:46.260 William Cheng: Now so simply like that then. So this way. When we return for this function we're going to return to the user space. We're going to use your user space. 269 00:35:46.440 --> 00:35:53.430 William Cheng: And now we're going to return to a different threads user space. So this guy's you know the previous user get preempted. And now we're going to run a different user threat. 270 00:35:54.360 --> 00:36:08.250 William Cheng: Now one of the user threat, you know, the use of the voucher already met a system called right so in that case what it will do is that it will come into the the top level, you know, our panel over here. And then we saw the the code in chapter three, is that he will 271 00:36:09.360 --> 00:36:12.870 William Cheng: You'll see if it's a system called if there's a system called it's going to go into the top 272 00:36:13.290 --> 00:36:17.910 William Cheng: Level truck handler. So over here is want to handle one of the 256 different tracks. 273 00:36:18.210 --> 00:36:26.400 William Cheng: There and in the end over here, we know we're going to return back into since this is the system call we know it's going to go back to the user. So I contrast. So again, we do exactly the same thing. 274 00:36:26.550 --> 00:36:36.180 William Cheng: We check if we should reschedule. We should give the CPU to somebody else. If we do, then again we add our software to run queue. And then we call through a switch to give up the CPU. So now he will return to a different user threat. 275 00:36:36.900 --> 00:36:45.420 William Cheng: That yeah so so the work of rescheduling over here is differ and it's done at the different processing time that so they're very, very simple solution. 276 00:36:46.230 --> 00:36:49.140 William Cheng: What about if you want to, you know, preamp a kernel threat. 277 00:36:50.040 --> 00:36:59.730 William Cheng: Okay, so, so that you know you are running the kind of their contacts you get a hardware interrupt and now will you return back into the contest. You want to be trying to a different, I do want to return to a difference about 278 00:37:00.300 --> 00:37:04.980 William Cheng: That. So we're going to take a look at the example for the, you know, full, full, full, full, full windows. 279 00:37:05.400 --> 00:37:17.730 William Cheng: So when windows in the corner of handed over here we're going to check in with him size is over. If the time size is over, we simply add the functional reschedule into the DP CQ. And then we're going to generate interrupt number two. 280 00:37:18.270 --> 00:37:26.520 William Cheng: Okay, so this way when we finished all the interrupt service routine over here for the hallway interrupt and then we're going to, you know, in one number two will get deliver when interim number to delivery. 281 00:37:26.760 --> 00:37:33.330 William Cheng: Is going to do all the default work. And one of the default work over here is going to be rescheduled so we're going to add current threat to the run. 282 00:37:33.510 --> 00:37:40.710 William Cheng: to to to to to run queue. And then we're going to cause switch to give out the CPU. So in this case, when we return back into a contest. We're going to run a different kernel threat. 283 00:37:41.760 --> 00:37:46.710 William Cheng: OK. So again, you know, Windows doesn't really cleanly as only a few lines of code and everything will work. Yeah. 284 00:37:49.320 --> 00:37:54.720 William Cheng: Alright, so that's the default work over here was a scene in the example of the for work. And that's what handling threat preemption. 285 00:37:55.170 --> 00:37:59.040 William Cheng: Okay, so the last thing that we need to do look at the interrupt overhears director processing. 286 00:37:59.610 --> 00:38:05.310 William Cheng: The directory processing. So something happens at it. So, so the directory processing over here, we can see that there are two different things. 287 00:38:05.550 --> 00:38:12.690 William Cheng: One is called a PC. So that's interrupt level. Number one, you know, for the windows for the Windows kernel. And the other one is unit. 288 00:38:13.020 --> 00:38:22.830 William Cheng: The unit signals. So yeah, whatever unit signals the unit signal is something happening inside the kernel. And then in this case, you make an appt call you follow through on the user space program. 289 00:38:23.040 --> 00:38:30.510 William Cheng: And then you make a function call on the user on your for your users behalf. Okay. And they return back into the kernel and you go back to what you're doing before. 290 00:38:30.870 --> 00:38:36.570 William Cheng: Okay, so, so that, so the director processing over here is that it's the basic idea over here. It's a callback function. 291 00:38:36.840 --> 00:38:42.510 William Cheng: Right, something happens at the kernel and then you specify the callback function to say when that's something have a call this function. 292 00:38:43.080 --> 00:38:48.900 William Cheng: Okay, this function can be a user space function. Why, in that case, he units. We call it a unique signal and also in Linux. 293 00:38:49.380 --> 00:38:56.820 William Cheng: Okay what if that particular function inside the Colonel. Well, then the Unix operating system eliminate them. They don't really provide a general mechanism for you to do that. 294 00:38:57.210 --> 00:39:02.790 William Cheng: Okay, but you windows, they have something called a synchronous procedure call. So in a way, the windows implementation is more general 295 00:39:02.910 --> 00:39:14.250 William Cheng: Because when something happens that a kernel and you will you handle the asynchronous procedure call in our servers and the number one over here. You can make them. I'll call it into the user space. Well, well, or you can actually call a kernel callback function. 296 00:39:14.790 --> 00:39:26.400 William Cheng: Okay. Ever since we don't have the other the sort of Windows source code. We're not going to talk about the example incarnate on the side. We're not going about talking about the example in Windows. But instead, we're going to talk about how Unix implement signal delivery. 297 00:39:27.000 --> 00:39:34.620 William Cheng: OK. So again, one thing that we need to sort of some sort of some sort of tried to learn over here is that, what does it really mean to borrow a user threat to deliver a signal. 298 00:39:35.340 --> 00:39:43.410 William Cheng: Howdy. Paul user threat right so so again so so so let's take a look at how to do this by looking at example. 299 00:39:44.160 --> 00:39:51.240 William Cheng: So the example over here, we are running a program over here, right. Here's a function called fund mains are called x x and why why is gonna call fun 300 00:39:51.420 --> 00:40:02.910 William Cheng: And then you know the IP over here is plenty right here and you're executing some code over here that and also the user space Poulin over here, specify a handler over here to say if the control C is press I want this function to get executed. 301 00:40:03.780 --> 00:40:13.710 William Cheng: Okay, so let's say for the sake of simplicity, the user space will not only has one square and that's where it's actually execute right here. So what we need to do that, we need to borrow this swear to execute this code right here. 302 00:40:14.520 --> 00:40:23.520 William Cheng: Okay, so what does that mean to borrow this, why don't we borrowing right. Hey, so yeah thread is just an abstraction. So in reality what we're borrowing what we hear is that we're going to follow that thread stack. 303 00:40:24.210 --> 00:40:38.940 William Cheng: To execute this function okay because you know this has little because redundancy. Right. You know when you know for you to ask you a Korean see over here, whether we need it. Well, we, we need a stock space guys are good and this is this particular user threat has a 304 00:40:39.960 --> 00:40:43.620 William Cheng: Has a user stock space, right. So, therefore, we're going to follow that stock space to actually this 305 00:40:44.280 --> 00:40:52.650 William Cheng: This function. Okay, so when you're executing code over here you have a stack space already and the tabular function over here is going to go up and down like crazy because you're gonna make 306 00:40:52.890 --> 00:40:56.490 William Cheng: Your function call over here, right at the time when you press Control, see what happened. 307 00:40:57.390 --> 00:41:04.770 William Cheng: There at the time when you first come to see over here. Then I'm going to suspend the user thought over here. And then we're going to go into that as the colonel to handle the interrupt service routine. 308 00:41:05.040 --> 00:41:10.560 William Cheng: Okay, so this side over here is going to go to sleep when it goes to see if we can borrow it to do to do something else. 309 00:41:11.040 --> 00:41:14.430 William Cheng: Okay, and also when it goes to sleep. We know obama do under the kernels that 310 00:41:14.790 --> 00:41:21.960 William Cheng: That's okay, let's start from the beginning. Over here, the sweat is actually doing over here. Here is what the user space that look like for this rare. 311 00:41:22.230 --> 00:41:27.990 William Cheng: What about the colonel step. What does the carnal cycle that the kernels that look completely empty so that you can actually make a system call 312 00:41:29.460 --> 00:41:33.390 William Cheng: Okay, so in order for you to make system going over your account on stock will be as empty and then the user right here. 313 00:41:34.410 --> 00:41:49.530 William Cheng: Right. So now when you press Control see over here. Boom, you're in the kernel, the user threat contacts over here. Where does this, you know, what's it going to be saved. Okay, so when you press countries to have you. Again, we saw before, where you get a hallway interrupt, you're gonna say 314 00:41:51.000 --> 00:41:58.200 William Cheng: You're gonna go to the current stack of the current other the colonel stack of the current executing a threat. I think I said the use of complex at the bottom of the Colonel's Doug over here. 315 00:41:59.490 --> 00:42:10.170 William Cheng: Okay. So, therefore, you know, when you press Control. See, you're going to try things out of Colonel, what we do is that, you know, this contacts over here. It's going to be saved at the bottom of the colonel stuck over here. Okay. So in this case, you know, all these informational 316 00:42:11.550 --> 00:42:27.000 William Cheng: Sorted about a movie. Yeah. So now the user thread over here is seeping okay that's that's the context of your seven about them over here. So now we noticed that the user actually press Control see okay so therefore we need to borrow that the user stuck over here to execute assumption. 317 00:42:28.080 --> 00:42:35.430 William Cheng: Because how to execute this function over here, right, in order for us to execute this function. We need the users we have users that we also need a kernel stack. 318 00:42:35.880 --> 00:42:46.050 William Cheng: Right, because one of the code over here. Make a system call with it makes a system called over here, it needs to find the Colonel's completely empty. So right now we have a problem here we have a user side. Look at this web Colonel cycle look like this. 319 00:42:46.770 --> 00:42:53.850 William Cheng: Okay, so they're in the wrong state, right. So what we have to do over here right now is that before we can we can follow this set, actually the signal handler over here. 320 00:42:54.060 --> 00:42:59.940 William Cheng: First thing that we need to do is that we need to get rid of the user threat contacts at the bottom, the kernels that. Okay, so where would you put it 321 00:43:00.450 --> 00:43:05.730 William Cheng: Okay. Some people will say, you might put into the third control blog or maybe there's some special Colonel data structure or something like that. 322 00:43:05.940 --> 00:43:12.630 William Cheng: But typically for Unix and Linux weather will do is that they will actually take this information and there was started into the user space stack. 323 00:43:13.380 --> 00:43:23.760 William Cheng: That they will actually pull the secret stack frame inside the user space dock over here and then they will copy the, the, the, the, you know the the same context for us and it saved into their own stack. 324 00:43:24.450 --> 00:43:26.250 William Cheng: Okay, so, so the picture will look like this. 325 00:43:26.430 --> 00:43:34.290 William Cheng: This is no as a sick frame over here. It's kind of a funny frame. So what do we do that on copy this information over here and now the colonel step over here will be will will be empty. 326 00:43:34.410 --> 00:43:41.910 William Cheng: And now the user space cycle we here I can build up a start for him over here for the signal handler and now I can start executing code for the signal handler. 327 00:43:42.600 --> 00:43:52.860 William Cheng: So I need to copy the data over here. Get rid of stuff at the bottom of the candlestick over here set up the stack frame for the signal hover over here and then now what I return over here. So, how to return back into the signal handler. 328 00:43:53.700 --> 00:43:58.680 William Cheng: Why, it's the same way I returned back into the user space program if you're on Intel you do return from interrupt. 329 00:43:59.400 --> 00:44:08.400 William Cheng: Whereas remembered you know the I return you know machine instruction is the only way you can go from the current Otter user space. So all you have to do is set up the CP register over there so that when they return over here. 330 00:44:08.580 --> 00:44:11.700 William Cheng: Instead of the IP pointed this function not appointed a different function. 331 00:44:12.780 --> 00:44:22.740 William Cheng: Okay, so definitely can do this while we may not call over here. You're going to execute the I return instruction over here so that you know that this go start executing. So at this point we have built a handler for 332 00:44:23.040 --> 00:44:32.220 William Cheng: That does the handler frame for the signal handle over here and also the bottom of the colonel stag is completely empty. Again, why do we need to have that because this card over here can make system call 333 00:44:33.210 --> 00:44:37.950 William Cheng: Guys, so therefore we need to make sure the Colonel Sanders MP over here, all the information is saved right here. And then in this case. 334 00:44:38.280 --> 00:44:43.800 William Cheng: That he can start executing this code, but so when you start executing a signal hover over here, the top of this evening. Hello. Bill is going 335 00:44:44.490 --> 00:44:57.090 William Cheng: Crazy because you're making see function call and eventually when you return over here. Where do you return to us in this case, will you return to what we hear is that this is a special friend that was set up. So will you return over here, you're actually going to return to a special 336 00:44:58.440 --> 00:45:06.030 William Cheng: You actually going to return to a special system call. Okay, so what do we do that you will set out the system call to be the return to be the return address. 337 00:45:06.510 --> 00:45:18.060 William Cheng: Okay, so this way when we, when we return for this function, the return address is going to be a system calls. So in the end, he will end up making a system called and this is of course know so I guess what this already is no as soon return 338 00:45:19.290 --> 00:45:28.080 William Cheng: Okay, so there's a function classic return and that's this isn't all so when you return, you know. So when you return on the signal huddled over here you and are you making a system called and boom, you're back inside of Colonel 339 00:45:29.040 --> 00:45:34.320 William Cheng: Okay, so we're back. He's not a car. What would you do right so now you're back inside the corner over here. So what I need to do is that 340 00:45:34.500 --> 00:45:41.010 William Cheng: This stock frame is gone. Right. So sort of separate oh here's God. So what I need to do is I need to go to the user space that will be here. 341 00:45:41.160 --> 00:45:47.850 William Cheng: We're all the information that I say that I need to copy it back to the colonel and this way I can reach back into the, the user space forward. 342 00:45:48.270 --> 00:45:55.470 William Cheng: Right, because I finished servicing the control see handler. OK. So now, and he will return back to the water was before, in order for me to go to 343 00:45:55.740 --> 00:46:03.450 William Cheng: Walk back to what it was before. I need to set up the Colonel's that exactly the way that I came in. So this way I can go in the reverse direction to return back into the user space program. 344 00:46:04.290 --> 00:46:07.620 William Cheng: Okay, so what I will do is I will go to the user stuck over here, take all this information. 345 00:46:07.860 --> 00:46:18.150 William Cheng: Copy it back inside the current over here. Right. And in this case, you know, get the same content over your web P. I. P. Point to the return address right here and now, again if I execute I return. 346 00:46:18.660 --> 00:46:25.260 William Cheng: You know, for, for us, so get over here. I need to go back into her abstraction layer a copy of the scope back into the 347 00:46:25.770 --> 00:46:29.130 William Cheng: The hall objectively or data structure and then eventually execute I return. 348 00:46:29.310 --> 00:46:41.910 William Cheng: And then I'll go by exactly what I was doing before. So when I finished doing that it will look just like this. Right. The last step over here is I return. I'm gonna go back exactly what was before. So if you notice carefully. This is exactly the same picture as I start with 349 00:46:43.020 --> 00:46:49.350 William Cheng: That. So I started with this day, right, and then I go into exactly this state, right. So right before I got need to go back to the same thing I need to go. 350 00:46:49.680 --> 00:46:54.210 William Cheng: And needs to return a kernel to be exactly what it was before. And then I can you know 351 00:46:54.600 --> 00:47:03.390 William Cheng: Go, go back to the user space. So the only difference between the state and the beginning stage and the final state over here is that now this has been bought execute the signal handler. 352 00:47:04.110 --> 00:47:09.870 William Cheng: Okay, so we bought the user space that we also ball the Colonel's back, just in case it's handled over here makes us a call. 353 00:47:11.040 --> 00:47:16.590 William Cheng: Okay, so this is how you borrow users are the are the bar user to add to execute signal delivery. Yeah. 354 00:47:18.690 --> 00:47:29.730 William Cheng: Alright, so we are you know done with this part of chapter five. So Chapter five, I guess that's one more part over here. Let me go there to take a look at chapter five. 355 00:47:32.880 --> 00:47:42.150 William Cheng: Chapter five. The next part of your scheduling. So we're going to go over this seventh after chapter seven. So this is almost for the end of the semester. Then we're gonna come back and take a look at scheduling. 356 00:47:42.570 --> 00:47:43.830 William Cheng: Guys. Now I'm going to take a break. 357 00:47:44.190 --> 00:47:55.650 William Cheng: So next time when we come back, we're going to go to chapter four over here. Look at storage management because so far, chapter four, we only look at a simple system, you know, sort of introduced to you that the life cycles for the threat and processes over here. 358 00:47:56.100 --> 00:48:03.780 William Cheng: We also show you there. So the introduction of the colonel threats and processes talking about copy on rod, you know, all that kind of stuff, and then 359 00:48:04.140 --> 00:48:07.290 William Cheng: So now we're going to start again. Chapter four, we're here. It's an introductory 360 00:48:07.560 --> 00:48:19.650 William Cheng: You know, sort introduced the optimism implementation to you. So now we're going to take a look at the storage management implementation as of the introduction of the storage management implementation in chapter four. Alright. Alright, see you after the break.