WEBVTT 1 00:00:01.920 --> 00:00:10.950 William Cheng: Welcome to lecture 21 Colonel three is do this Thursday. If you have co from previous semester, don't look at them. Don't copy them best to get rid of it. 2 00:00:11.550 --> 00:00:18.930 William Cheng: So again, you know, the message should be cleared don't cheat. So remember even Colonel three is only worth 10% of your overall grade. 3 00:00:19.320 --> 00:00:28.590 William Cheng: Okay, and a great step is 9% so you know even if you lose the complete 10% you know you're a only going to get into an A minus. So again, it's 4 00:00:29.310 --> 00:00:40.830 William Cheng: You know, it's, it doesn't work that much grading guidelines. The only little gray. So please remember to do all the self grading the README file and tried to get as many points as you can. I'm sort of going to mention that today. 5 00:00:41.460 --> 00:00:50.280 William Cheng: After submission. Make sure you verify your kernel submission is there. Again, this is very important for you to to do to do this tab, we cannot do with where you you have a do it yourself. Yeah. 6 00:00:50.640 --> 00:00:55.290 William Cheng: And there's something wrong, you should fix it as soon as possible. Yeah, and 7 00:00:55.770 --> 00:01:03.060 William Cheng: So as it turns out, lectures 21 is the final lecture. And the reason is that, you know, in week four we had, we had an extra lecture. 8 00:01:03.360 --> 00:01:07.680 William Cheng: So therefore, this Thursday, there will be no lecture, right, because we already know. We already give that 9 00:01:08.370 --> 00:01:14.220 William Cheng: And also there's no discussion section this Friday because the hub of the last programming assignments due 10 00:01:14.640 --> 00:01:23.550 William Cheng: On Thursday, so it will be too late. Anyway, right but but if you have questions about the remaining part of kernels three, you know, feel free to send me, you know, post to the class Google group. 11 00:01:24.930 --> 00:01:29.910 William Cheng: Alright, so for Colonel three so please understand that, you know, we, if we the grading guidelines. 12 00:01:30.210 --> 00:01:37.620 William Cheng: You know, by default, we're going to assume that you can run the user space shell. So that means that you know in a proper on all you have to do is to run a spin in it. 13 00:01:38.340 --> 00:01:47.850 William Cheng: Okay, so, so, so, you know, if you can run as been in it from from prefer for any progress. That's great. You don't have you don't you don't think a shop or anything. 14 00:01:49.980 --> 00:02:02.220 William Cheng: colonel colonel three your submissions, you simply run it's been in it. Any progress and all the commands that's mentioned in the kernel three grading guidelines, they will all be typed in from the user upon the user space shell. 15 00:02:02.910 --> 00:02:08.580 William Cheng: Okay, so that's going to be the assumption but if there's any reason for any reason that you can not run has been in it. 16 00:02:09.540 --> 00:02:12.300 William Cheng: Okay, then in that case you need to grab as many partial credit as 17 00:02:12.720 --> 00:02:20.520 William Cheng: As possible. Okay, so again regretting guys very, very carefully. Some of the commands has to be run from the, from the user level show or you get no credit 18 00:02:20.940 --> 00:02:32.730 William Cheng: For example, Section C section sees Keisha so all the console, so, so, so, so if you can run as being in a while, then you're not going to get any points. Okay, but but section be you can actually run everything is that you can be, you know, from Keisha 19 00:02:34.020 --> 00:02:41.010 William Cheng: Okay, so. So in that case, you know you need you need like a shell command one for every sub test right one for hello one for 20 00:02:41.310 --> 00:02:53.250 William Cheng: Example, like that every one of these K shell commands. You know, you see, so, so, so again, in case you cannot run as been as this is the thing you need to consider this right. Otherwise you can you can skip, you know, listen. 21 00:02:53.760 --> 00:03:01.260 William Cheng: Listen to me, to me, for now, that if you cannot run a spin in it, you need to create as many K shell command as possible and for each case shell command. 22 00:03:01.500 --> 00:03:14.520 William Cheng: Run the user space program, you know, by, by creating a child process instead of child process called Colonel exactly he go run, you know, hello program or whatever or whether you need to run and then come back into the user space program and then you go back to Keisha again. 23 00:03:15.810 --> 00:03:28.290 William Cheng: Okay, so. So in part b I guess part of the grading. I live there are many, many times, right, you need to create as many Keisha commands as there are tests and then document and very, very carefully inside you really need to tell the greater how to get all these partial credit 24 00:03:29.460 --> 00:03:38.700 William Cheng: Okay, so, so my recommendation will be like the first test, you know, the first step testing essentially be just call that test be one, right. So if the greatest happy one, you're gonna get partial credit for 25 00:03:38.970 --> 00:03:49.350 William Cheng: So you're going to get full credit for the second one can copy to MP3. And I said, rob a similarly in de de de to D3 or something like that. So I guess in Section D. The first test. 26 00:03:49.710 --> 00:03:55.950 William Cheng: I can remember as probably DFS test right but again we the the grading on a very, very carefully. It says that if you cannot 27 00:03:57.150 --> 00:04:02.340 William Cheng: You cannot run BFS test from the user level show the most you can get is 50% of the credit 28 00:04:03.210 --> 00:04:10.680 William Cheng: Okay, so you're not getting the diamonds that you're still eligible to run a you know the the running from the show. So using occasional command, you know, maybe you call a D. 29 00:04:10.950 --> 00:04:18.150 William Cheng: amp D around will run DFS as again document that very, very carefully kind of the greater what can enter type in order to run which test. Yeah. 30 00:04:18.930 --> 00:04:30.660 William Cheng: So, so, so, so, so remember that when the greater, greater, greater, greater is not allowed to modify a single line of your code because that will cause you know that will cause why 10 points of 20 points. 31 00:04:31.380 --> 00:04:37.620 William Cheng: Okay. So, therefore, you got to make sure use Keisha command over there so they can you can try to get as many partial credit points as possible. 32 00:04:38.010 --> 00:04:46.740 William Cheng: There. So again, if you can run it's been in it. Then, then don't do any of these things that the greater when I run any case show, you know, Colonel three if you spin it is working. 33 00:04:47.220 --> 00:04:49.320 William Cheng: Okay. Otherwise, you should take this approach. Yeah. 34 00:04:49.890 --> 00:04:57.390 William Cheng: Alright must provide extensive documentation, read me about it. Tell greater how to grow a reading getting Allah and fully understand and ask me questions. If you're not sure 35 00:04:57.660 --> 00:05:04.650 William Cheng: Don't assume things right, anything that you're not sure, ask me a question, because once you, you know what, what's the deadline comes around, it's going to be too late. 36 00:05:05.280 --> 00:05:11.940 William Cheng: Okay modification to your code, they all going to cost points if you ask the greater to change your code is going to cost you a major amount of points. Yeah. 37 00:05:12.750 --> 00:05:14.610 William Cheng: Alright, so if you have questions, send me an email. 38 00:05:15.450 --> 00:05:29.310 William Cheng: The final exam is next Tuesday. All this fourth and final exam is going to be exactly the same format as the midterm exam I will post the final exam coverage of basically everything after the midterm exam plus chapter five. Now, 39 00:05:29.820 --> 00:05:40.500 William Cheng: So, so again the same logistic rights take home exam open book, open notes. And also, you know, I will ask you to sign a Honor Code pledge for the final exam. 40 00:05:40.740 --> 00:05:44.940 William Cheng: I don't know if you notice that for the you know the the place that you have side is just for the mature. 41 00:05:45.450 --> 00:05:52.800 William Cheng: Okay so final exam. I'm going to ask you to sign a different a pledge, even though the content is going to be very, very similar, except that he says, For the final exam. Yeah. 42 00:05:53.280 --> 00:06:00.270 William Cheng: If you don't send me the honor code pledge, you are not eligible for the final exam because you didn't promise me that you will not choose. So therefore, you're not going to get the final exam. 43 00:06:00.480 --> 00:06:11.430 William Cheng: And your final exams. Not going to be, it's going to be zero and you are not even eligible for Incomplete, incomplete meetings that you know is that you didn't take the final is that because of illness or because of a family emergency 44 00:06:12.030 --> 00:06:25.950 William Cheng: Okay, if it's because you're not eligible to take it because it didn't sign the final pledge, then your final exam score will be zero or so please take this very seriously. I don't really understand why people want to send the place on the last day okay because mail and 45 00:06:27.210 --> 00:06:32.760 William Cheng: So so anyways. He the last day, you have internet problem, then in that case you will not get a final exam, you don't get a zero. 46 00:06:33.180 --> 00:06:37.380 William Cheng: Okay, so as soon as I send you the instructions you should do it as early as possible, then 47 00:06:38.100 --> 00:06:44.610 William Cheng: The final exam. I just, they will be the same as the midterm. See the June 30 news item in the class website. 48 00:06:45.150 --> 00:06:50.670 William Cheng: So again, you should sort of, you know, practice, you get things ready, just in case you're going to lose the Internet. 49 00:06:51.240 --> 00:06:59.010 William Cheng: You know, we are ready to start to some your exam. So again, be a little paranoid, but they'll be super paranoid. Yeah. So, so be familiar with the procedure. 50 00:06:59.550 --> 00:07:11.640 William Cheng: So since everybody did it you know pretty well. There are there are more than one students submit the final exam late and I follow my rules to the dog, you know, five points for every minute of late submission 51 00:07:12.690 --> 00:07:22.740 William Cheng: Okay, so, so, you know, for most people, you know, all their submission, you know, maybe in time, right, you have three minutes to submit after 1040 and again after the beginning of 1040 not the end of 1040 52 00:07:23.220 --> 00:07:29.580 William Cheng: Okay, so you're starting with the first, second or 1048 you should stop writing your exam and you should spend the next three minutes you're making a submission 53 00:07:30.240 --> 00:07:35.310 William Cheng: Date and if you are able to make the submission during those three three minutes, then you don't have to record anything 54 00:07:36.150 --> 00:07:43.560 William Cheng: Okay, but if it turns out again. If it turns out that you have internet problem in that case you need to use the zoom recording as approved. So this means that 55 00:07:43.770 --> 00:07:48.060 William Cheng: You know, at that time, if you try to sign into zoom will be too late because you have internet problem you can sign into zoom 56 00:07:48.750 --> 00:07:56.910 William Cheng: Okay, so you have to sign into zoom at the beginning of the exam before the exam start. So this way, just in case. Bad things happen. You can still record things on your local drive 57 00:07:57.390 --> 00:08:07.680 William Cheng: Okay, so, so, okay, you don't need to sign in at a later time. Right, so yeah. Follow the steps over here and you got to be okay. But if you don't, if you haven't tried it, then you're going to get nervous and you got to, you know, mess things up then then then 58 00:08:08.340 --> 00:08:14.430 William Cheng: Then, then you should really practice that. Alright, so there's no rehearsal for the final is that'd be there's going to be just like a midterm exam. 59 00:08:14.640 --> 00:08:23.460 William Cheng: But if you are not sure about the procedure and if you'd like to have a rehearsal. Just send me email. And then again, I'm going to send you a rehearsal for your final exam. 60 00:08:24.360 --> 00:08:29.850 William Cheng: Okay, but if you don't request that you're not going to get it. But if you request it. I will try to probably do it on Monday at 10 o'clock. 61 00:08:31.290 --> 00:08:31.650 William Cheng: Okay. 62 00:08:32.760 --> 00:08:39.960 William Cheng: All right, the final exam is going to have an extra kind of question that we don't have in the mid term, you know, the new question types of me be calculation. 63 00:08:40.590 --> 00:08:48.510 William Cheng: So I guess you know we're talking about scheduling right now. Sometimes you need to compute a schedule. So in that case, you have to do calculation. 64 00:08:49.350 --> 00:08:57.660 William Cheng: So, so, for example, you also need to be able to calculate things like average waiting time, you know, to put a standard deviation of the waiting time over those kind of stuff. 65 00:08:58.020 --> 00:09:07.470 William Cheng: Okay, but, you know, so, so, so, so you need you need to be able to do the calculations correctly, according to what you have learned in this class because again. 66 00:09:07.740 --> 00:09:11.880 William Cheng: It doesn't matter what you learn the internet and you know you have to follow the recipe in this class. Yeah. 67 00:09:12.840 --> 00:09:18.330 William Cheng: If you don't have a calculator. I mean, this is the open book, you can actually use the internet calculator or something like that. 68 00:09:18.960 --> 00:09:24.030 William Cheng: You can also leave these things simple fractions. Right. A simple fraction is a number divided by another number 69 00:09:24.390 --> 00:09:30.930 William Cheng: So if there's anything that you need to add or something like that. You seem to perform addition and subtraction. Yeah. But if you want to leave at a simple fraction. That will be fine. 70 00:09:31.440 --> 00:09:37.350 William Cheng: If you have a square root. If you don't want to pay square where you can say square root root of a fraction and they'll be perfectly fine now. 71 00:09:38.700 --> 00:09:47.130 William Cheng: Today we're going to talk about the scheduling algorithm Australia scheduling scheduling. There are two ways to present it. One is to follow the textbook. The other ways to follow the lecture. 72 00:09:47.760 --> 00:10:01.710 William Cheng: Lecture 21 which is today's lecture for Australia scheduling, you must use the algorithm that's presented today and not the one in the text, will you follow these procedures and types of what you don't get no credit. OK. So again, you have to learn the stuff you know from the lecture. Yeah. 73 00:10:03.270 --> 00:10:20.880 William Cheng: Alright, so let's proceed with our final lecture of the summer session. So last time we talked about some, you know, a schedule for them, you know, first come first serve you know shortage offers earlier, you know, I guess the 74 00:10:22.110 --> 00:10:29.850 William Cheng: The shoulders remaining time next right and that was a round robin and also the multi level feedback queue right lots of veggies talked about quite a few 75 00:10:30.660 --> 00:10:34.200 William Cheng: So now we're going to sort of ask a question on a general purpose operating system. 76 00:10:34.710 --> 00:10:40.740 William Cheng: Okay, what kind of a scheduled you do you typically have right because I'm a general remember audiences and just like your laptop or your cell phone. 77 00:10:40.950 --> 00:10:45.840 William Cheng: It needs to do a lot of different things, right. You can be compiling code at the same time while you're listening to music. 78 00:10:46.110 --> 00:10:57.240 William Cheng: Or you're watching a video or you are surfing the web or these kind of stuff. So what kind of schedule is actually good for a general purpose every system. I mean, clearly you cannot find the optimal scheduler for for general purpose audiences them. 79 00:10:58.140 --> 00:11:10.980 William Cheng: So typically what we found is that, you know, also so that you know for, you know, for for this kind of system. They typically have these kind of characteristic is going to be time slice right last time was sort of saw talking about time slicing. It's a really good way to go. 80 00:11:12.150 --> 00:11:13.500 William Cheng: You know, I've been a baby. 81 00:11:14.490 --> 00:11:22.500 William Cheng: Because make things look fair all the, you know, you know, all the job. They're all making progress. It's good to go. And also, if you have interactive 82 00:11:22.710 --> 00:11:30.060 William Cheng: You know, people doing stuff. Right. Some of them can be CPU hawk. Some of them is going to be sort of somebody's going to be CPU bound. Some of them are going to be IO bound 83 00:11:30.450 --> 00:11:40.680 William Cheng: So again, using a priority basis them seems to work pretty well. Okay. And also you want to reward jobs that give us the CPU very quickly to sleep on IQ or go sleep on a 84 00:11:42.390 --> 00:11:46.050 William Cheng: sip on your tax you so this way you can increase the throughput of the schedule. 85 00:11:46.500 --> 00:11:52.950 William Cheng: Guys again. All these things are good day. And also, you know, typically this is going to be preempted, especially if you're using time slicing 86 00:11:53.160 --> 00:12:02.580 William Cheng: By definition, you're doing preemption, right, because the devil preemption is that you are running some things that the CPU and all of a sudden you're not done but you switch you give the CPU to somebody else. 87 00:12:03.150 --> 00:12:10.860 William Cheng: Right. So if you're doing time slicing after time slice and then the CPU will give it to somebody else. So therefore time slicing implied you're doing preemptive scheduling. 88 00:12:11.520 --> 00:12:16.530 William Cheng: Okay. So, typically in a general purpose ordinances, then we see that they all have these kind of characters day 89 00:12:16.980 --> 00:12:23.820 William Cheng: The one we just talked about, you know, the windows multi level feedback you right it's time slides right within every party class. 90 00:12:24.210 --> 00:12:28.470 William Cheng: They use time slicing clearly they are priority level over here and there is in preemptive schedule. 91 00:12:29.220 --> 00:12:37.830 William Cheng: There. So again, you know, Windows users schedule. I did not exactly the way that we have described, but again, Windows keep changing. So we don't really know exactly what they're using at any incident, the time 92 00:12:38.280 --> 00:12:40.440 William Cheng: But they sort of based on the multi level feedback you 93 00:12:41.250 --> 00:12:49.800 William Cheng: Know, and we mentioned also last time the priority is really not what we're looking for. Right. We want to say that the interactive user always should have higher priority than the background job. 94 00:12:50.010 --> 00:12:54.870 William Cheng: But again, the interactive user can round in a CPU bound job in that case it will block all the other jobs over here. 95 00:12:55.230 --> 00:13:03.120 William Cheng: So maybe that's really not not not not the best way to go. Right. But people sort of like to use, you know, sort of a instead of sort of different heuristic to determine 96 00:13:03.510 --> 00:13:10.320 William Cheng: You know what needs to be run at higher party there. So once you start, you know, using party then then you're using a heuristic. 97 00:13:10.830 --> 00:13:17.340 William Cheng: Then people start using all kinds of heuristics to try to improve the performance of the schedule. Right. So, for example, some people can actually use 98 00:13:17.700 --> 00:13:28.530 William Cheng: You know, the long term, you know, history of a particular job if you run a pretty good job every day at 4am gay. Maybe you can actually collect some statistics about this job and use that to help you to make better scheduling decision. 99 00:13:29.220 --> 00:13:31.830 William Cheng: OK. So again, people actually go go go to that extent. 100 00:13:32.220 --> 00:13:43.770 William Cheng: By looking at the behavior, you know, over time, you know, for a particular job at the wrong to you and use that to help them maybe to set you know quantum or something like that. All kinds scheduled as good screen decision can be made. 101 00:13:44.220 --> 00:13:53.580 William Cheng: Based on these kind of heuristics. Because again, we're not going to, you know, in this class. We're not going to talk too much here. So here is the because once you start doing stuff here. So you can have all kinds of crazy 006 yeah 102 00:13:54.330 --> 00:13:57.840 William Cheng: So maybe for more events operating system class, they will talk more about that. 103 00:14:01.530 --> 00:14:04.200 William Cheng: Alright, the next kind of scheduling, we're gonna 104 00:14:04.800 --> 00:14:13.170 William Cheng: We're going to talk about is the one that scheduling for fairness right again. The example that we that we keep giving is that, you know, if you, you know, pay one 10th of a 105 00:14:13.470 --> 00:14:20.310 William Cheng: Of a machines that a cloud. You want to get one 10th of the CPU want to get one 10th of everything. Yeah, so the question is that, you know, you know, 106 00:14:20.970 --> 00:14:28.440 William Cheng: Since you pay just like everybody else you want to get your fair share of the CPU. So how can a scheduler sort of guarantee, you know, something like that. 107 00:14:28.770 --> 00:14:32.760 William Cheng: Because typically, if you think about scheduler, you know, if you have a work preserving 108 00:14:33.270 --> 00:14:42.630 William Cheng: A scheduler, as long as somebody else wants to CPU more than you do while then in the end going to end up giving you know more share of the CPU to somebody else, because how do you actually guarantee that 109 00:14:43.140 --> 00:14:50.580 William Cheng: You get exactly what you pay for. Okay, the testimonials use this particular you know example. It's a shared server, for example, Mr server inside of cloud. 110 00:14:51.060 --> 00:15:00.690 William Cheng: You and four of your friends. So if I were you. Each one contribute $1,000 towards the server. Okay. Since you contribute exactly one fifth of the price of the machine. 111 00:15:01.290 --> 00:15:09.450 William Cheng: You know you rightfully feel that you own 20% of it. Okay. So, therefore, if all of you guys are running right. You want to make sure you get 20% of the CPU now. 112 00:15:09.990 --> 00:15:18.150 William Cheng: The example we have goes live again, typically the way we sort of thing about is that you can run multi threading, you know, we're going to split evenly divided the CPU about all the threads. Yeah. 113 00:15:18.360 --> 00:15:26.490 William Cheng: But what if your friends are into multi threading and you're not okay, your friends, they will run a fourth to other programs and you run a single threaded program. 114 00:15:27.330 --> 00:15:32.190 William Cheng: Okay, so in this case right there will be 17 threats. Right. So in this case, if you are doing, you know, 115 00:15:32.640 --> 00:15:42.390 William Cheng: Server a fairness type of scheduling so that every thread get equal amount of CPU. Well, in that case, your friends, they're going to get for 17th of the CPU and you're going to get 117 of the CPU. 116 00:15:43.140 --> 00:15:50.100 William Cheng: Right, and then you complain. You say, Hey, you know, I want to get 120 percent of CPU. How come I'm getting, you know, one fourth of what everybody else is getting 117 00:15:50.550 --> 00:15:54.240 William Cheng: Okay, so your friends say, Well, why don't you run multi threading. Okay. Lisa, but I don't want to 118 00:15:55.140 --> 00:16:07.440 William Cheng: Okay. I mean, you actually have the right to say I don't want to run off as reading, but I just want to make sure that I get 20% of CPU. Okay, so, so, so in this case, how can a scheduler be designed so that he will actually guarantee fairness to you now. 119 00:16:08.790 --> 00:16:16.110 William Cheng: All the solutions actually very simple. It's called a lot. We have a scheduler. Okay, so all we can do is that the scheduler would issue 20 tickets 120 00:16:16.410 --> 00:16:23.790 William Cheng: And then what we'll do is that you have five people you know you're sharing the CPUs equally. So what it will do is it will give every, you know, every owner five 121 00:16:24.510 --> 00:16:34.020 William Cheng: Everyone or four tickets. So you get forward together. Each for each for your friends. They all go for 40 days a year. You have 2020 tickets and every time when the CPU become available. 122 00:16:34.410 --> 00:16:36.870 William Cheng: What a scheduler would do is as the schedule will run a lottery. 123 00:16:37.410 --> 00:16:48.270 William Cheng: Okay, so what if it doesn't, I'll put all 20 tickets in a box over here and then it was spin it and then it will pick a random ticket out of the box over here and then we'll say why the winners number 15 or whatever, whoever owns number 13 124 00:16:48.540 --> 00:16:53.460 William Cheng: Gets running out of CPU. Okay. So you get two lines that the CPU for time slides and then 125 00:16:55.680 --> 00:17:04.350 William Cheng: When you finish your time flies. Again, we're going to put your ticket back into the box and we're going to, you know, to, to another scheduling again and I'm going to pick out run it again and whoever owns that ticket good runs out of CPU. 126 00:17:05.670 --> 00:17:09.000 William Cheng: So in our case, since you have four tickets and your friends that each one of them. 127 00:17:09.480 --> 00:17:16.530 William Cheng: For tickets, then every time we perform other the lottery. There's a one third chance that you will use that data, you will win. 128 00:17:16.740 --> 00:17:22.800 William Cheng: But since you have only wants to add every time I'm going to give the CPU to center and your friends. They are forth where they can decide to give 129 00:17:23.010 --> 00:17:27.570 William Cheng: You know CPU two different sizes. I want to, or if they want to give us up to saying that it's completely up to that. 130 00:17:28.530 --> 00:17:36.690 William Cheng: Right. So in this case, in the end, everybody will will be using the CPU one fifth of the time. Okay, so, so, so, so is this is this fair 131 00:17:37.590 --> 00:17:42.720 William Cheng: I mean sounds really fair. Right. You know the problem with the lottery scheduling algorithm over here. So how do you actually implement it. 132 00:17:43.470 --> 00:17:49.740 William Cheng: Okay. So in this case, I only have 20 tickets. That's not so bad. What do I have plenty of what about 1 million tickets 133 00:17:50.280 --> 00:17:55.260 William Cheng: Okay, I have, you know, I'm running, you know, 100 700 over here. And then, you know, they do. 134 00:17:55.620 --> 00:18:04.920 William Cheng: Some people pay more, somebody will pay that I'm going to end up with 1 million tickets every time when I go, you know, to perform and Audrey. I'm going to pick out a ticket and then I need to figure out who owns the ticket. 135 00:18:05.670 --> 00:18:13.950 William Cheng: Okay, so I can use the hash table to improve my performance. You know, I can use the tree or something like that. But in the end, it's going to be very expensive for me to actually perform the lottery. 136 00:18:15.240 --> 00:18:19.170 William Cheng: Okay, so, so, so, you know, there's nothing wrong with a concept. The question is how to actually implement this. 137 00:18:21.630 --> 00:18:32.580 William Cheng: So, so one of the sort of solution. We're going to look at. It's called, it's called dry scheduling. Okay, so this is also known as the proportion of scarce I share scheduling, you're going to get run on 138 00:18:34.350 --> 00:18:39.690 William Cheng: You're going to get an opportunity to our CPU, as you know, proportional to the number of shares that you have 139 00:18:40.110 --> 00:18:48.960 William Cheng: Okay, so number of shares that you have is a number of lottery tickets that you have. So if you all three tickets another threat on six tickets. That means that the other threatening to run twice as often as you do. 140 00:18:49.410 --> 00:18:51.840 William Cheng: Right, because it's proportional to the number of sure that you have 141 00:18:52.770 --> 00:19:03.180 William Cheng: To answer the question how to implement it in 1995 there's a paper written by the operating system researcher or they come up with the scheduling called the strike schedule malware them and that's what we're going to see next guy. 142 00:19:03.600 --> 00:19:09.840 William Cheng: In the in 2007 12 years later Linux decided to adopt try scheduling. 143 00:19:10.920 --> 00:19:16.380 William Cheng: Okay, it takes Linux 12 years to figure out the hey strike schedule actually pretty good. And this is actually not 144 00:19:16.980 --> 00:19:27.300 William Cheng: This is actually very typical for opportunities and research somebody come up with some great idea in research and he will take people 10s of years before they can actually say that this is actually a pretty good idea, which is running into real system. 145 00:19:28.470 --> 00:19:37.200 William Cheng: Okay. And we saw before we sort of talked about. There's a scheduler activation models, you know, to, to do to avoid 146 00:19:38.970 --> 00:19:43.620 William Cheng: A protein version. Right. So again, that one is in research, we don't really know when anybody will pick it up. 147 00:19:43.740 --> 00:19:51.480 William Cheng: Because you know when you try to pick a scheduler and things like that. You gotta be very careful. Maybe it's good for one thing. What if it's bad for a lot of things. So, India, you really cannot use it. 148 00:19:52.020 --> 00:19:56.880 William Cheng: Okay, so, so let me actually liked it so much. They call it the completely fair scheduling algorithm. 149 00:19:57.480 --> 00:20:07.110 William Cheng: But, but, but, again, please remember, you know, even when it's when Linux thing is completely fair. Some people will still completely compliant. It's not fair, right, because fairness in the end it's a very difficult concept that 150 00:20:07.860 --> 00:20:12.210 William Cheng: Right, so I'm going to sort of describe the you know the the the strike scheduling. 151 00:20:12.690 --> 00:20:18.030 William Cheng: The textbook described as using something called meter processes and we're not going to go with that approach. 152 00:20:18.450 --> 00:20:30.870 William Cheng: So what happened is that when proposal, given their first taught this class, you know he he has a way to explain sure I scheduling. I like his way of explaining things much better. So therefore I adopted his slides. And I use you know I 153 00:20:32.040 --> 00:20:43.470 William Cheng: Always uses notation, you know, to describe Skype scheduling. So in the final exam if I asked you a question about strike schedule, you have to use the one that's covered in the lecture today and not the one textbook. Right. 154 00:20:44.970 --> 00:20:53.580 William Cheng: Alright so what to start scheduling over them. So again, it has all the characteristic of a general purpose, you know, a scheduler. It's time slices party basis preemptive 155 00:20:54.450 --> 00:21:06.090 William Cheng: So, so, so, so since this time slides. We're going to schedule based on time slides. So every time slide at the end of the time flies when CPU become available. We're going to pick a threat, based on the party. Right. So there's no time. So I party. 156 00:21:06.750 --> 00:21:13.890 William Cheng: A party scheduling algorithm. So, except that typically, you know, typically, when we talk about party. We want to run the script with the highest priority. 157 00:21:14.460 --> 00:21:18.870 William Cheng: Guy. So this guy will we're going to sort of do things in a slightly different way. So every thread is going to be 158 00:21:19.260 --> 00:21:26.400 William Cheng: assigned a dynamic priority know as the past value. Okay. We don't call it a priority because party means that the higher priority should 159 00:21:26.760 --> 00:21:32.070 William Cheng: Should should run first. So in this case, the past value up here at the one with the lowest pass value should go first. 160 00:21:32.850 --> 00:21:41.430 William Cheng: Okay, so just because you know it's not the highest one so they don't call the party. But India. And so, partly based scheduling whichever thread that own the, the lowest part of the past value. 161 00:21:42.090 --> 00:21:54.060 William Cheng: Get the right instead of CPU for the next time slice. Okay. So, therefore, we're gonna have a single queue right here is a single queue over here, right. So inside the cube over here, all the jobs are sorta based on your past value. 162 00:21:54.960 --> 00:22:01.620 William Cheng: There's over here. The past barely made go to this one equal to 511 25 you know 1 million over here at the end over here. 163 00:22:01.920 --> 00:22:10.950 William Cheng: Okay, so they are sorted by the past values and this can become very, very simple. All we need to do is to pick up the first job and then we're running out of CPU RAM. So next time when the time. So as we kind of 164 00:22:11.310 --> 00:22:15.840 William Cheng: Went when the class is over. I will deceive you become available we pick the next one and pick the next one. 165 00:22:16.200 --> 00:22:25.590 William Cheng: Well, so the only thing that you need to do is that did the determine that this job, will you finish Ronnie inside the CPU for 100 slides will you finish it. What is going to be its new path value. 166 00:22:26.820 --> 00:22:32.760 William Cheng: Okay, because you know if the past value still today we're going to keep still running the job over and over again. So in that case it will not be time slice right 167 00:22:33.060 --> 00:22:38.760 William Cheng: So, so what we need to do is that we need to update the past value whenever a job over here finishes time. SIGHS 168 00:22:39.240 --> 00:22:49.770 William Cheng: Okay, so this is how do we update the past value. Well, we're going to update the past value, according to the number of lottery tickets that you have. Okay, if you have a lot of lottery ticket. So in this case, how should we update the past value. 169 00:22:50.640 --> 00:23:00.060 William Cheng: That if this thread, you know. So again, instead of their control blog, we can store the number or a lottery ticket that you have, if this has a lot of law retake. So in this case, what you should do is you come back. 170 00:23:00.510 --> 00:23:02.790 William Cheng: With a very, very small increment of the past value. 171 00:23:03.270 --> 00:23:09.930 William Cheng: OK, so the income in your in your in your past value when you finished running out of CPU. That's called a strike. That's what it's called strike scheduling. 172 00:23:10.110 --> 00:23:16.140 William Cheng: So if you have a lot of lottery ticket. So in this case, it will come back with a small Australia. We're going to increment the past value by a small amount. 173 00:23:16.350 --> 00:23:23.640 William Cheng: If you don't have too many lottery tickets and this guy is going to send you all the way to the end of the run to you over here. So in that case, Australia will be very, very large. 174 00:23:24.390 --> 00:23:33.120 William Cheng: Okay. So, therefore, you know, the number of lottery tickets and destroy value over here. It's going to be inversely proportional to each other. OK. So again, that's the basic principle. Yeah. 175 00:23:33.600 --> 00:23:45.630 William Cheng: Alright so got every sort of US assign a strong value over here you know the values of computer according to the distribution of tickets and a lot of rescheduling scheme right again. Specifically, the more tickets that you have 176 00:23:46.110 --> 00:23:55.740 William Cheng: The small Australia have other smaller than number of tickets that you have the longer the strike value. Now, and the struggle is over here are integers. Why did. Why are they integers. 177 00:23:56.610 --> 00:24:08.700 William Cheng: Maybe the scheduler need to run very fast. You know, so all the scheduling algorithm that we saw. We saw so far are they all run very fast. And if you need to perform floating point computation that is really going to slow things down. 178 00:24:09.660 --> 00:24:13.680 William Cheng: Okay. So I think in the time he performed by 40 point you know the 179 00:24:14.460 --> 00:24:23.730 William Cheng: You know, arithmetic or you can actually compute, you know, hundreds of the fixed point you know with with a. So, therefore, you want to avoid floating point number as much as possible, right, especially 180 00:24:24.150 --> 00:24:26.940 William Cheng: Inside a scheduler. We only want to use integers. 181 00:24:27.330 --> 00:24:37.980 William Cheng: Okay. So, therefore, you know, you're going to take the number of tickets that you have. You go through some calculation on an event, you need to convert them into an integer because using a floating point number is that the scheduler is going to be on this editable there. 182 00:24:39.360 --> 00:24:51.240 William Cheng: Alright, so the reservation boat, you know, in every iteration or every time slides at the end of the time slides. When the CPU become available you schedule the thread with the smallest pass value which is at the head of the queue and then 183 00:24:51.840 --> 00:24:54.810 William Cheng: Also, you need to sort of set a global variable to say who are, you know, 184 00:24:55.920 --> 00:25:00.360 William Cheng: So, so it's almost like when you go to go, you know, go go to one of the government agency over here. 185 00:25:00.750 --> 00:25:05.250 William Cheng: They show your number. Now I'm serving number 32 and you look your ticket number 99 186 00:25:05.520 --> 00:25:14.790 William Cheng: So there was a long way to go. Okay, so therefore they will also update this thing called the Global price value. So as we begin to see what is the goal. What is the current, you know what, what 187 00:25:15.480 --> 00:25:17.010 William Cheng: What is the current job as being served. 188 00:25:17.430 --> 00:25:27.720 William Cheng: Okay, and they don't want to see how to actually use this value. So whenever you take a job and you running out of CPU, you're going to change the global pass value to be the past value of the job, then you just moving out of CPU. 189 00:25:28.350 --> 00:25:31.260 William Cheng: Yeah, all right. And then, then you run it. 190 00:25:32.040 --> 00:25:37.140 William Cheng: And then in this case there's, you know, once you start running the time slides over here you can give up the CPU voluntarily. 191 00:25:37.320 --> 00:25:40.830 William Cheng: Or if you don't give up the CPU. In that case, you know when when the time will happen. 192 00:25:41.040 --> 00:25:49.530 William Cheng: When your time is over, then again the CPU is going to become available. So what we'll do is that you don't want the time size is over. We're going to increment the threats pass value by strike value. 193 00:25:50.130 --> 00:26:00.030 William Cheng: Okay, so again this is just one line of code right past plus or equal to try and that's how you have to do so in this case the past value and drive value, they're all part of the second job block. 194 00:26:00.450 --> 00:26:07.590 William Cheng: Right. So in this case you just go to the second chakra and you increment the past value by, you know, by the strike. Okay. And then this guy. 195 00:26:08.160 --> 00:26:16.890 William Cheng: you'll move this job back into the school over here. You're going to insert them at the right position so that you know the Q will be sorta, you know, based on the past value. 196 00:26:17.490 --> 00:26:23.460 William Cheng: Okay. They also some fancy data start to that you can use drive for, you know, for for Q like this. You can also use the priority to write the 197 00:26:24.000 --> 00:26:35.460 William Cheng: article is the self sorting queue. So in this case, you know, every time you know when you add something to the priority queue, it will it will take the survey. So every time we started we know from a you always remove the one with the smallest past value. 198 00:26:37.230 --> 00:26:50.490 William Cheng: And then you just you just move this wherever because, again, very simple algorithm. Right. So again, you know, when we look at a good scheduling algorithms, the scheduling algorithm have to run very, very fast because we don't really want to schedule the overhead to slow down. 199 00:26:51.900 --> 00:26:53.250 William Cheng: Slow down your machine. Okay. 200 00:26:54.600 --> 00:27:00.930 William Cheng: Alright, so we're gonna take a look at this using an example. Okay, so we're gonna actually just take the number of tickets over here. We're gonna, you know, 201 00:27:01.230 --> 00:27:08.820 William Cheng: The taken through reciprocal event. And we're going to say this drive value is going to be exactly, you know, proportional to one over the number of tickets 202 00:27:09.510 --> 00:27:15.030 William Cheng: So in this case, the stripe out. So the other way can sort of think about is that stripe value multiple number of tickets going to equal to one. 203 00:27:15.330 --> 00:27:22.110 William Cheng: Okay, so therefore destroy value and and I would take is inversely proportional to each other that and now you've got to make them into integers. Right. 204 00:27:22.650 --> 00:27:28.920 William Cheng: Alright, so let's take another example over here. So we have three threads over here are our at the monkey or three jobs that are ranking over here. 205 00:27:29.220 --> 00:27:41.070 William Cheng: They belong to a, b, and c and he has three tickets. He has to ticket CS one ticket. So again, the relative numbers over here. They are important, right. So, so the number of tickets is 32122 206 00:27:41.310 --> 00:27:49.290 William Cheng: That means that he needs to run inside the CPU twice as often as messy and he needs to run inside a CPU three times often so I see 207 00:27:50.070 --> 00:27:56.430 William Cheng: Okay, so that's what's important about this picture again they do, they sort of paper proportionally. And that's how they end up with different number of tickets 208 00:27:56.790 --> 00:28:04.440 William Cheng: Yeah. So in this case, what will be the strike right so if you use this equation over here then Australia we one third ones have and then one over one. 209 00:28:05.100 --> 00:28:14.880 William Cheng: OK. So again, since they are so this is it will look like this right 131 half of one over here. But again, we don't like building number appointed by number of here. Now we need to change them into integers. 210 00:28:15.120 --> 00:28:20.670 William Cheng: Then we actually need to change that mean to integrate a smallest possible over here, you know, so that you know 211 00:28:21.120 --> 00:28:25.200 William Cheng: This sort of calculation will actually be sort of easier to do. 212 00:28:25.620 --> 00:28:29.550 William Cheng: So how do you actually make them into integer that are still proportion on exactly the same way. 213 00:28:29.730 --> 00:28:37.260 William Cheng: When this guy. We're going to look at the denominator for all these three branches and then multiply the smallest common multiplier. The all the denominator. When I saw 214 00:28:37.560 --> 00:28:45.030 William Cheng: This guy down denominator is one and two and three. What is the smallest common multiplier is equal to six. Right. You multiply them together is six. 215 00:28:45.600 --> 00:28:51.060 William Cheng: So in this case, you know, we're going to multiply all them by six guys what we're gonna get 216 00:28:51.600 --> 00:29:00.660 William Cheng: We're gonna get equals to this is equal to two, this is equal to three, and is equal to six. Right. So again, when you multiply by the smallest common modifier you guaranteed to get all integers. 217 00:29:01.470 --> 00:29:05.130 William Cheng: Okay, so that's why we multiply them by the smallest comment multiplier. Yeah. 218 00:29:05.760 --> 00:29:12.630 William Cheng: All right, so we're gonna end up with two three and six over here so you can, again, you can do a sanity check if I multiply these two number, the number of tickets motivated by strike. 219 00:29:12.840 --> 00:29:17.580 William Cheng: I'm going to get a constant, right. So in this case, we multiply them together, all you are going to get is equal to six. 220 00:29:19.320 --> 00:29:21.900 William Cheng: Alright. So again, it's very important to check your like there, especially 221 00:29:22.260 --> 00:29:28.620 William Cheng: During the final exam as you to to do all this kind of sad. You're going to make sure that you compute a smallest common multiplier and then it's not, you know, 222 00:29:28.770 --> 00:29:35.010 William Cheng: Figure out what the true value of that drive value has to be an integer. Otherwise, there's no partial credit for you then. 223 00:29:35.850 --> 00:29:39.840 William Cheng: Alright, so now we know the value over here. Right, so no can actually run our 224 00:29:40.530 --> 00:29:44.730 William Cheng: Program. So at the beginning. So let's say that we're going to assume that job aid ABN three 225 00:29:44.940 --> 00:29:53.220 William Cheng: They're all at the run queue. So in that case, what is their initial pass value. Right. So this guy, you know, either assign them some initial pass value. It can be anything. I want to assign them into 226 00:29:54.030 --> 00:29:58.650 William Cheng: Okay, so I can assign any value to them. So for this example, I'm going to call. I'm going to do that, one, two, and three. 227 00:29:59.520 --> 00:30:06.510 William Cheng: Okay, in the exam I can give a completely different number. Again, you have to work, you know, with the example, based on the. Those are the numbers given an example. 228 00:30:06.900 --> 00:30:15.120 William Cheng: Okay, so in this example is this example here is gonna be here. He's gonna be here see is going to be here and Pascal is W one, two, and three. So again, I just pulled this number of 229 00:30:15.390 --> 00:30:22.650 William Cheng: These are random number comma word and the example can work with any kind of value or any kind of has value to start with. Right. You just have to run the algorithm. Yeah. 230 00:30:23.700 --> 00:30:33.600 William Cheng: Alright, so let's do this right, he has the past Radio one p as possible to see his past value of three over here. Again, I'm not. I'm getting this number, not because he has highest 231 00:30:33.960 --> 00:30:36.930 William Cheng: The most number of tickets via second is just a random assignment. 232 00:30:37.350 --> 00:30:47.010 William Cheng: There on the right hand side over here. I'm going to keep track of every time slides. Who's going to be the winner who gets to run inside the CPU now. So now we're iteration zero times last 233 00:30:47.610 --> 00:30:54.480 William Cheng: Iteration one times x equal to one number over here. Who do we run out of CPU. Right. Again, we look at the wrong Q and we see who has the smallest 234 00:30:54.690 --> 00:30:59.670 William Cheng: Value one this case will go to the head of the queue, the head of the queue is going to be the wild with a smallest past value. 235 00:31:00.300 --> 00:31:10.650 William Cheng: Guys, so therefore we're gonna we're gonna get rid of this one from the rescue and that run this inside the CPU. We also on the right hand side, we're going to be clear that in the duration. Number one is going to be the winner. 236 00:31:11.250 --> 00:31:21.960 William Cheng: Guy, so therefore it's not look like this right is going to run out of CPU over here is a winner in row wine. So now we're going to keep running on to the class is over when this is over. We're going to increment A's. 237 00:31:22.290 --> 00:31:31.410 William Cheng: Pass value by the stripes value a strike value over here is equal to two i. So, therefore, one plus two equal to three. And then we need to insert it back into the wrong here at the right place. 238 00:31:32.100 --> 00:31:40.050 William Cheng: Okay. Where should we insert job at over here. Should we insert job, a right here. A three right here and put it behind behind. See if you can see there's a pie. 239 00:31:41.010 --> 00:31:44.760 William Cheng: Okay, there's a tie. Should we put a behind. See, or should we play in pharmacy. 240 00:31:45.630 --> 00:31:52.830 William Cheng: Ok ok for the purpose of this class C is already inside around here. So it's kind of rude to cut in front of CC has exactly the same show value. 241 00:31:53.250 --> 00:32:01.290 William Cheng: Sorry, I see as exactly same has value. So in this case, you know, the way we're going to break ties that if somebody in front of you had the same has value because you Q behind that. 242 00:32:01.800 --> 00:32:10.860 William Cheng: Okay, so there was this case we're required to put a you know about behind see. OK. So again, that will be a requirement for this class there. So we're done. It will look like this. 243 00:32:12.060 --> 00:32:16.110 William Cheng: So he is going to be behind. See, even though they're tied to the seas already inside Ranchi 244 00:32:16.590 --> 00:32:19.950 William Cheng: Okay. Alright, so now over here time slides to go to to 245 00:32:20.280 --> 00:32:30.690 William Cheng: You know, what do we do, we do we take the one with the smallest personality and we'll run inside a monkey. So in this guy's again the queue is sorta so therefore we're simply going to move this one into the CPU, so be have to over here is running out of CPU. 246 00:32:30.900 --> 00:32:33.660 William Cheng: And the second round over you're going to remember be is the winner. 247 00:32:34.110 --> 00:32:46.020 William Cheng: There so therefore you will have like this right when the time size is over. We're going to increment these past value by destroy value. He started out as you go to three, two plus three equals five. Then in this case be of fives going to go right here. Right. 248 00:32:47.070 --> 00:32:50.700 William Cheng: Now, so this one is pretty straightforward, right. So what we've done it will look like this. 249 00:32:51.150 --> 00:32:55.950 William Cheng: Okay, time slots. Number three, who do we run inside of CPU are again over here, even though there's a tie. 250 00:32:56.190 --> 00:33:03.900 William Cheng: We, you know, since there are stories that are run queue, which is going to pick the first job over here. I was going to run inside the CPU. So therefore, now see will be a 251 00:33:04.230 --> 00:33:11.790 William Cheng: You know, the winner over here. So we're going to look like this. Okay. So far it looks really boring. It's almost like we're running round robin A, B and C. Yeah. 252 00:33:12.150 --> 00:33:16.950 William Cheng: All right at the end of the time size over here see his past values when they be encouraged by destroy value. 253 00:33:17.400 --> 00:33:25.800 William Cheng: Strike equal to six over here is a season going to go to the end over here. See, has the past value night become nine because three plus six equals nine. So it will look like this. 254 00:33:26.280 --> 00:33:34.680 William Cheng: Okay iteration number four we're going to run a inside of CPUs, or a three goes there. This one is gone, is going to be the winner and it will look like this. 255 00:33:36.600 --> 00:33:43.440 William Cheng: At the end, at the end of the slides over here. We're going to increment eight by the by, by destroy value the stripe value over here, equal 256 00:33:43.800 --> 00:33:56.010 William Cheng: To three plus two equals two, five again there's already a job five, you know, the job be in front of you with the same pass value. So in this case, we're going to actually move past job see over here and then get it behind job job be 257 00:33:57.030 --> 00:34:02.400 William Cheng: OK. So again, there's a tie. You need to get behind you know people that you tie with. So this guy will end up with the situation over. Yeah. 258 00:34:02.760 --> 00:34:10.140 William Cheng: Okay, and then time slots. Number five over here we're going to run be inside the CP over here with the clip be is the winners are like this. 259 00:34:10.380 --> 00:34:14.700 William Cheng: I mean, again, so far it looks like we're being wrong Robin, you know, pretty boring over here. 260 00:34:15.060 --> 00:34:22.890 William Cheng: When time sizes over he's going to get increment by the stripe value. It's true value equal to three, three plus five equals a. So, therefore, please don't come right here. 261 00:34:23.130 --> 00:34:35.940 William Cheng: And then in this case you will have the past about equal to a. So there's nothing like this guy's a. Now again, I'm Celeste number six. Want to give the CPU to a so he is going to run inside of CPU over here. So this guy's a is going to be the winner. 262 00:34:37.260 --> 00:34:50.190 William Cheng: Of so therefore you know it's going to look like this when the time side is over is going to increment the past value by destroy value is equal to two plus five people to seven. So therefore I am going to be at the head of the wrong key over here and I was like this. 263 00:34:51.960 --> 00:34:55.680 William Cheng: Okay, so now I'm going to declare that at this point. Okay. 264 00:34:56.160 --> 00:35:01.020 William Cheng: This configuration is exactly the same as the original configuration. What was the original configuration. 265 00:35:01.260 --> 00:35:06.930 William Cheng: Right. The original configuration is a, b, and c over here is pass your one and he has passed value to 266 00:35:07.140 --> 00:35:18.030 William Cheng: And see, it has value or one over here. Why do I say they're exactly the same, right, because these past value is one greater than a SEC has value is exactly one greater than be over here again be is greater than 267 00:35:19.410 --> 00:35:27.330 William Cheng: One greater than a and this is one better than B and they're in the wrong here in the in exactly the same order. Okay, so what I can do is I can actually take all the 268 00:35:27.630 --> 00:35:31.290 William Cheng: All the jobs over here, subtract the past value from all the threads. 269 00:35:31.710 --> 00:35:37.920 William Cheng: By by six. I'm going to eventually and I was one, two, and three. So, therefore, again, it's going to be exactly the same as the original value. 270 00:35:38.250 --> 00:35:41.430 William Cheng: Okay. Is it okay if I take all the past value and reduced by the same amount. 271 00:35:41.910 --> 00:35:48.510 William Cheng: Yeah, I'm going to end up with exactly the same schedule so that we know is I can actually reduce the buy anything I want. So if I reduce all the past value by six. 272 00:35:48.690 --> 00:35:58.110 William Cheng: Then in this case I'm going to end up with exactly the same configuration at the beginning. So what does that means that the cycle that I saw before he is doing good repeat over and over and over again, right, what is going to be the cycle. 273 00:35:58.590 --> 00:36:05.280 William Cheng: Why it's going to be a cycle of six iterations over here. And during this cycle over here, how many times does a guest running out of CPU. 274 00:36:05.640 --> 00:36:12.180 William Cheng: A run three times be run two times and C, round one times exactly proportional to the number of tickets at all. 275 00:36:12.990 --> 00:36:23.940 William Cheng: Okay, so if I repeat this pattern over and over and over again, then I know that, you know, on the average is going to run three times more often and C and B is going to run run twice. Twice as often as I see 276 00:36:25.080 --> 00:36:33.150 William Cheng: Okay. So, therefore, this is why Linnaeus call this completely fair schedule now where then you get to running out of CPU as often as the number of tickets that you have 277 00:36:33.540 --> 00:36:46.050 William Cheng: Will proportional to the number of tickets that you have. Yeah. Alright, so this component of distribution or tickets over here right again every six cycles over here. The going to repeat and remember the six is the you know the smallest common no 278 00:36:47.100 --> 00:36:53.490 William Cheng: Wait, wait, maybe that has nothing to do with it. Maybe this is a coincidence. So in this case, every six cycle sort of value. Yeah. 279 00:36:59.190 --> 00:36:59.520 William Cheng: All right. 280 00:37:00.540 --> 00:37:01.620 William Cheng: What do you do you have a nucleus. 281 00:37:02.760 --> 00:37:11.910 William Cheng: Writing threat okay with rice into the the the wrong food over here, right. The example that we saw over here. These three slides one forever eventually one of the search over here. 282 00:37:12.360 --> 00:37:20.250 William Cheng: You know, he's going to give up the CP voluntarily and he will leave it on to you and now you have two threads. Right. So again, whatever, two thirds. As you continue to do exactly the same algorithm over here. 283 00:37:20.760 --> 00:37:28.230 William Cheng: It will continue to work. Okay, but what if you have a new set of arriving to rank you what what what what past values you do assigned to 284 00:37:28.980 --> 00:37:39.630 William Cheng: That one of the great thing about history scheduling is that this can be easily resolved the needs to our over here will be allocate the global past value. So in that case, you will actually get very, very close to the hazard rank you 285 00:37:40.140 --> 00:37:53.100 William Cheng: Okay, maybe a header until you're going to have a few slides are happy that the high or the past are you so pretty soon you're thrilled to be here will be run inside a CPU, you know, even though you might you might have a very long list. OK. So again, 286 00:37:54.360 --> 00:38:08.760 William Cheng: Is this fair is is unfair. OK. So again what we what we need to do is that we need to get this gives us a chance right inside of CPU, why do we, why should we do that because what if this to give them the CPU right away because this threat is sorry 287 00:38:10.140 --> 00:38:18.450 William Cheng: What is this job is IO bound job. So what do we do say we're running out of CPU and before the time size is always, I should have to give up the CP voluntarily and go sleep on Io queue. 288 00:38:19.110 --> 00:38:26.400 William Cheng: Right. So in that case, you know, we need to give this, we need to give this job, a chance running out of CPU as quickly as you can. Because it turns out to be a really good job. 289 00:38:26.730 --> 00:38:36.810 William Cheng: Okay, if it turns out it's a CPU bound job and that case why that is that after you run inside to see people one time size. In that case, you will increment, you know, you'll pass it by the show value in this case you will go to the right place. 290 00:38:37.500 --> 00:38:43.410 William Cheng: Okay, so therefore is perfectly okay at the beginning. Over here you give it a highest party so they will run right away. 291 00:38:43.860 --> 00:38:50.550 William Cheng: Okay, again, the window schedule is the same thing when a job arriving to the reviews. So typically what we can do is, I will get this assign it to the highest priority. 292 00:38:50.730 --> 00:38:55.530 William Cheng: It will get a chance to run inside a run queue. And if it turns out that it's a CPU bound job, you will get downgraded 293 00:38:56.040 --> 00:39:06.270 William Cheng: OK. So again, the same idea. We hear you know because you want to. You really want to, you know, sort of take a chest, just in case it's a CPU. It just doesn't K. The job is IO bound job yeah 294 00:39:07.440 --> 00:39:13.230 William Cheng: If it turns out that sort of a job is really nice, you know, to the, you know, to, to the to the scheduler. 295 00:39:13.710 --> 00:39:21.720 William Cheng: Yes I Oban job. It's going to give up the CPU very quickly. So in that case, next one. When it comes back into the monkey. We actually want to even you know so treat even better. 296 00:39:22.020 --> 00:39:27.150 William Cheng: Okay, so maybe there's a way to actually pump is party. Okay. So, for example, one thing that you can do is that, you know, 297 00:39:27.390 --> 00:39:36.180 William Cheng: You know, if you don't use up your entire time slice right the time size over here is that we only use a fraction of the time size. So, for example, FOB here maybe maybe 10% 298 00:39:36.780 --> 00:39:44.250 William Cheng: Then in that case when we try to increment your past value will only encourage 10% multiply by you, bye bye bye bye bye Australia value. 299 00:39:44.970 --> 00:39:56.880 William Cheng: Okay, so this way. Next time, will you come back into the monkey. What we get you going again move even closer, you know, to the heads of the run cute. Okay. You might even move past, you know, have a baby beyond, beyond, beyond, beyond all the job that they're actually the 300 00:39:58.050 --> 00:40:03.480 William Cheng: Head of you is that a run through that. So, again, in this case, we try to encourage the CPU to be 301 00:40:03.990 --> 00:40:14.280 William Cheng: You know as much, you know, seek IO bound as possible. And this way. We're going to give them preferential treatment want to run it over and over and over again. So, this way we can have a really high throughput at the monkey that 302 00:40:15.330 --> 00:40:24.000 William Cheng: All right. Oh, we're sort of asked a question over here is the better than the multi level feedback you are. So again, it all comes to the question of how do you actually assign a priority in a multi level feedback you 303 00:40:24.180 --> 00:40:28.380 William Cheng: And also here. How do you determine, you know, how many tickets you know does each thread has 304 00:40:28.920 --> 00:40:42.330 William Cheng: You know so inside a sheer server if you if you purely, you know, assign tickets based on the amount of money they they pay. Well, in that case it will be pretty you know pretty fair because you know if you pay twice as much, you know, case you will use the CPU twice as often. 305 00:40:43.590 --> 00:40:52.350 William Cheng: So in that case, you know, it could be better than a multi level few guys queue. But again, the multi level through that. Q. We haven't really tell you exactly how you figure out the priority. Okay. 306 00:40:52.980 --> 00:40:59.430 William Cheng: So unless you can actually assign dollar amount to threats, you know, you still have the same problem of how to allocate you know lottery tickets 307 00:41:00.300 --> 00:41:10.350 William Cheng: Threads over here. And so, India, you know, to compare these kind of scheduler might be difficult to come through to compare. But India will know that Microsoft is going to be for a while way and Linux prefer the other way. Okay. 308 00:41:12.030 --> 00:41:17.280 William Cheng: All right, isn't sorting the past value slow, right. How do you actually saw something. Okay, so we noticed sorting. 309 00:41:18.210 --> 00:41:24.180 William Cheng: Them all granted. But again, if you use a priority queue data structure the priority queue data shark is a self sorting data structure. 310 00:41:24.570 --> 00:41:29.490 William Cheng: So in that case, anytime you try to insert something to the party. Q. Again, if you have taken CSI 70 311 00:41:29.880 --> 00:41:36.660 William Cheng: You probably see that analysis where every time when you try to ensure something to the party to is going to cost you order log log base to event. 312 00:41:37.020 --> 00:41:42.810 William Cheng: That and every time when you try to delete the minimum element from that Q is also going to cause you order a log base to a bad 313 00:41:43.200 --> 00:41:49.230 William Cheng: Guys, okay, if n is equal to 1000 a lot based to end his own equal to 10 so neck is actually pretty good. 314 00:41:49.830 --> 00:42:01.080 William Cheng: Okay, much better than sorting McHugh every time we're all performing searches are we providing services to our he's gonna cost you on the order of an OK. So again, this data structure is the preferred data structure to be used with Dr. Scheduling 315 00:42:03.750 --> 00:42:07.740 William Cheng: Alright, so, so that you have a scheduler and 316 00:42:08.580 --> 00:42:17.850 William Cheng: I think this is actually a good time to break so so actually we don't have to schedule those left and they are you know they are for the real time you will for the real time real time system. 317 00:42:18.330 --> 00:42:24.030 William Cheng: So we're going to take a break now and the next part. We're going to look at the you know the last to schedule it