WEBVTT 1 00:00:01.920 --> 00:00:12.809 William Cheng: Okay, this is the second part of lecture 21 so we have two more scheduler to look at. So they are both useful for scheduling heart real time system. 2 00:00:13.410 --> 00:00:19.860 William Cheng: So again, what's special about the heart real time system is that would a job arrive at the run queue to carry a deadline with it. 3 00:00:20.190 --> 00:00:30.630 William Cheng: And if you don't finish running this job by the deadline, then disaster is going to appear. Okay so disaster is going to happen. So therefore, it's very important for us to figure out 4 00:00:31.200 --> 00:00:37.650 William Cheng: You know whether we can satisfy all the deadlines or not. So in the end, we're basically we're trying to come up with a schedule. 5 00:00:38.100 --> 00:00:48.210 William Cheng: Tried to satisfy a bunch of constraints and in this, in this instance, it's it's it's trying to make sure that every job, you know, meet the deadline. OK, so 6 00:00:48.840 --> 00:00:54.990 William Cheng: The cases that we're going to look at in this class, since this is the introductory class we're going to look at the unit. The unit processor case. 7 00:00:55.410 --> 00:01:04.500 William Cheng: Because typically for the multiple CPU case. The problem is very complicated. So they're typically NP complete. So we're not going to look at and maybe for more advanced 8 00:01:05.190 --> 00:01:11.130 William Cheng: You know, operating system class. They're also classes. I think in doubly. They also teaches real time system class. 9 00:01:11.490 --> 00:01:16.170 William Cheng: They will also look at some other you know more advanced schedulers guys. So again, we just look at a basic ones. 10 00:01:16.800 --> 00:01:21.600 William Cheng: There will be to schedule. We're going to look at. One is called rate monotonic scheduling. I'm pretty fancy term. 11 00:01:22.140 --> 00:01:36.240 William Cheng: So it's used for scheduling cyclic chores or periodic tasks. So these are the things that happens over and over again. So for example, if you want to monitor a nuclear reactor. So in that case, what would your computer do right so you're probably going to take some temperature reading 12 00:01:37.290 --> 00:01:42.000 William Cheng: You know, and then you try to sort of control, you know, some kind of a knobs over there. 13 00:01:42.300 --> 00:01:48.900 William Cheng: You also probably going to take some moisture reading some pressure reading all kinds of reading over here and then you need to do some computation. 14 00:01:49.170 --> 00:01:56.460 William Cheng: And you have to do all these reading up periodically and then every time when you take a measurement. There's a fixed amount of work that you have to do. 15 00:01:57.180 --> 00:02:08.130 William Cheng: That. So there were the idea over here is that every job will be here will come with two different parameters. One is the execution time. So this is when you run instead of CPU. How are you going to run. And then the second one is called a period 16 00:02:08.640 --> 00:02:17.100 William Cheng: Right. So, for example, ti over here can be equal to two and then PL very equal to six. And that means that every six seconds, you want to run this job for two seconds. 17 00:02:17.580 --> 00:02:25.320 William Cheng: Okay, so in that case, you know, if I just running this job every six seconds, you have to keep running this job for two seconds, you're going to eat up one third of the CPU. 18 00:02:25.890 --> 00:02:32.640 William Cheng: Okay, so if you end up you have too many jobs, how, you know, if you add up, you know, the if you add them all up is going to use more than 100% of CPU. 19 00:02:32.850 --> 00:02:37.950 William Cheng: One. Don't forget it. There's no way for you, for you, for you to come up with the schedule that will satisfy all the deadlines. 20 00:02:38.250 --> 00:02:49.410 William Cheng: Okay, so if you, you know, so, so, so, so sorry about this ratio. If it's less than 100% then in that case we need to sort of determine whether there's a schedule that can satisfy all the deadlines. Yeah. 21 00:02:50.250 --> 00:02:57.570 William Cheng: Alright, so the other schedule. We're going to look at his Earliest Deadline First this one can be used to schedule job that are not periodic 22 00:02:58.020 --> 00:03:04.410 William Cheng: Okay, so every job simply come with a deadline. There's no the there's no period associated with a job. 23 00:03:04.770 --> 00:03:13.530 William Cheng: If you have taken CSI 70 or you probably seen approved to say that the Earliest Deadline for a scheduler is actually the optimal scheduler, you know, under certain conditions. 24 00:03:13.830 --> 00:03:21.810 William Cheng: You know, in the real time system. Maybe those condition may not be met. But, but, but I guess is the schedule is up monitoring condition, you know, somehow, we need to try it. 25 00:03:22.140 --> 00:03:29.460 William Cheng: Just to see if we can satisfy all of their lives, right. So we're going to see examples of these two schedulers in action, so they can actually compare them. Yeah. 26 00:03:30.900 --> 00:03:35.940 William Cheng: Alright, so first you know what about interrupts right you know this is going to take away CPU cycle. 27 00:03:36.270 --> 00:03:41.490 William Cheng: So the typical assumption. Again, this is an introductory class we're going to assume that interrupt doesn't interfere with the schedule. 28 00:03:41.820 --> 00:03:47.910 William Cheng: Okay, so one thing that you can do is that you can sort of think about, you know, whenever you get a higher rate interrupt like a clock in Iraq or something like that. 29 00:03:48.150 --> 00:03:57.060 William Cheng: How much time are you going to spend in handling the clock interrupt and then the rest of his time. Like, who knows that. So you can subtract all the interrupt service routine time. So this way, what you're left 30 00:03:57.300 --> 00:04:03.000 William Cheng: With the remaining CPU capacity and you want to use the remaining CPU capacity to to to to run all the other jobs. 31 00:04:03.540 --> 00:04:11.790 William Cheng: Okay, so that will be one sort of simple way to take away the the you know the the exclusion time uniform, you know, observers routine. Yeah. 32 00:04:12.390 --> 00:04:21.180 William Cheng: The other thing is that, you know, we're going to assume that you know you know every six seconds, you have to run your job with two seconds. So how do we know that the job is going to run for two seconds. What did we come up with two seconds. 33 00:04:21.990 --> 00:04:27.600 William Cheng: Then the job execution time is really difficult to predict because of all kinds of caching behavior. 34 00:04:27.780 --> 00:04:33.000 William Cheng: If you have a, you know, especially like the one we're familiar with. Right. Well, you get a hit in the translation go with that buffer. 35 00:04:33.180 --> 00:04:36.600 William Cheng: You're going to perform much better than if you don't get a hit and a translation of us have offer 36 00:04:36.840 --> 00:04:47.250 William Cheng: On the CPU side. There's also different kinds of CPU some, some, you know, some of the caches are inside the CPU some locations outside of the CPU. So in that case it will make the execution time very difficult to predict 37 00:04:47.700 --> 00:04:54.240 William Cheng: Okay. So typically, again, what would be one thing that we can do that, we can actually use the worst case analysis or maybe use the average case analysis. 38 00:04:54.600 --> 00:05:05.160 William Cheng: So this way. We're going to assume that the execution times actually predictable. But in reality, it's really difficult to create to predict. Okay, so, so we're going to assume that this can be done. So we can do our analysis. Yeah. 39 00:05:06.690 --> 00:05:15.930 William Cheng: Alright, so let's take a look at the first scheduler. The rain monotonic scheduler. So this one is only used to schedule the periodic tasks or sickly chores. Yeah. 40 00:05:16.440 --> 00:05:25.710 William Cheng: So every job has a period and every job has execution time if the execution time of the job is bigger than the period. Well, then in that case, forget it. Right. Because if every six seconds. 41 00:05:25.920 --> 00:05:30.600 William Cheng: You have to run this job and it will take you seven seconds to run this job, then you know that the schedule is not going to work. 42 00:05:31.260 --> 00:05:34.890 William Cheng: Yeah, so then we're going to assume that he is going to be less than or equal to API. 43 00:05:35.490 --> 00:05:49.530 William Cheng: So to API. It's, it's a number is a percentage of the time that the CPU is spending serving this particular job right. If t is equal to two and P is equal to six. Then the CPU spends one third of its time just doing this job. 44 00:05:49.860 --> 00:05:55.200 William Cheng: Yeah, so this is also known as the utilization, or the duty cycle for your photo job number hide. 45 00:05:55.950 --> 00:06:01.290 William Cheng: So I guess duty cycle is more like a, you know, hardware term or engineering terms of like that. 46 00:06:01.620 --> 00:06:08.250 William Cheng: Sort of the picture. Look at this. Right. If you have picked up every job that that that runs two seconds or every six seconds and you just draw a picture like this. 47 00:06:08.730 --> 00:06:12.240 William Cheng: You know what it's trying to run it will run for two seconds, and then he will rest for four seconds. 48 00:06:12.420 --> 00:06:25.080 William Cheng: And then he will run for two seconds, and he will wrestle four seconds or something like that. So this picture. Why do you have a duty cycle of 33.33% or eating up one third of the CPU. So again, same thing the utilization, or the duty cycle mean the same thing. 49 00:06:26.310 --> 00:06:31.710 William Cheng: So that will give us another constraint. If we add up all the utilization for all the job that we're supposed to run 50 00:06:31.980 --> 00:06:41.520 William Cheng: Okay, if it turns out to be less than one. Well, then there's a possibility that a schedule work if it turns out that this number is bigger than one. What, then, basically, there's no way for us to satisfy that requirement. 51 00:06:41.970 --> 00:06:49.290 William Cheng: Okay, because if you add up all the duty cycle. If it's greater than 100% well then in that case we don't have enough CPU power. Okay, so you're not guys, what do we do 52 00:06:49.770 --> 00:06:58.890 William Cheng: Well, there are two things that you can do. You can either get rid of some jobs, there may be some of jobs and I wasn't that important. So maybe we could get rid of them. If you keep getting rid of the Java we hear, then the number of jobs. 53 00:06:59.310 --> 00:07:03.900 William Cheng: The number utilization is going to be smaller, smaller at some point the sub will be less than one. 54 00:07:05.040 --> 00:07:08.610 William Cheng: Okay, so in that case, we're going to, you know, maybe we will maybe again we can try to sort of find a schedule for 55 00:07:08.970 --> 00:07:14.730 William Cheng: The other thing that you can do. So you actually get a faster CPU. If you get a faster CPU. The period is still going to be the same thing. 56 00:07:15.060 --> 00:07:20.490 William Cheng: Rather period doesn't change, but in this case the execution time will actually get shrink. So therefore, the some OB. OB smaller 57 00:07:21.000 --> 00:07:29.490 William Cheng: Okay, so hopefully if you keep shrinking a small enough where we hear you feel, you know, as long as you're willing to spend more money to get a faster CPU, then the utilization over here is going to be less than one. 58 00:07:30.090 --> 00:07:38.670 William Cheng: Okay, so, of course, if you're working with a customer, you need customer to approve that you can budget, you can recruit. We can't hear the budget because nothing's gonna be a little more expensive that 59 00:07:39.990 --> 00:07:46.590 William Cheng: So, so again. So, these, these going to be the basic requirement. The room on the schedule is actually a very, very simple scheduler. 60 00:07:47.400 --> 00:07:52.830 William Cheng: You know, this is how it works. Every choice I is handled by a thread with party one over PR 61 00:07:53.100 --> 00:08:00.240 William Cheng: So basically what we're gonna do. We're going to use party scheduling. The longer the period, a lot of the party, the shorter the period, the higher party and then we're done. 62 00:08:00.720 --> 00:08:05.730 William Cheng: Okay, our schedule is going to be presented, which means that you know when a higher party job arrive. 63 00:08:05.940 --> 00:08:14.430 William Cheng: If you're running inside you. If you're running a lower part job inside of CPU. We're going to preempt I job, put it back into the run queue. And we're going to always be running the highest party job. 64 00:08:15.480 --> 00:08:23.490 William Cheng: There so it's going to be preempted and party scheduling and then we're done very, very simple scheduler again monopolies ism, we'd like very, very simple schedulers yeah 65 00:08:24.630 --> 00:08:38.460 William Cheng: So people actually studied good so that they were actually do a lot of math behind it and they found out that if you have the some of the realization. If it's less than or equal to the equation on the right over here. Then re Mon on a schedule is guaranteed to satisfy all the deadlines. 66 00:08:39.540 --> 00:08:47.100 William Cheng: So again, it's very powerful statement to say if you add up the realization over here, he compare against the equation on the right, where n is a number of job that you're scheduling. 67 00:08:47.520 --> 00:08:54.480 William Cheng: Okay. If this number is less than the equation over on the right you can schedule these jobs to start it anytime and then you're going to satisfy all the deadlines. 68 00:08:54.930 --> 00:09:05.190 William Cheng: Then what about the what what is the equation look like. So on the right hand side over here are the numbers over here for a equals two, one, as long as the utilization is less than one, but obviously it's going to work. 69 00:09:05.460 --> 00:09:17.880 William Cheng: Right. But when n equal to two over here, then this go to zero point a to a floor as then goes to infinity, the right hand side over here approach natural log of two. So, in that case is going to be 0.6931 70 00:09:18.750 --> 00:09:23.310 William Cheng: Okay, so, so again this is you know this one when when the number Giacobbe infinity. So I'm going to say 71 00:09:24.360 --> 00:09:34.620 William Cheng: You know, if you have a bunch of job if you add up all their utilization. If it turns out to be less than 0.6931 then you know that the right amount of hundred scheduling is guaranteed to work. 72 00:09:35.070 --> 00:09:39.360 William Cheng: Okay, basically you can schedule them anywhere you want, and then all the job will satisfy the deadline. 73 00:09:39.990 --> 00:09:45.900 William Cheng: Guys, again, this very powerful statement that will tell you, under what condition great monotonic scheduling will always work. Yeah. 74 00:09:46.680 --> 00:09:54.930 William Cheng: Right. Well, if it doesn't work, guys. So in that case, you know, so, so if you add up all the utilization. What is this between the equation over right over here, and between one 75 00:09:55.530 --> 00:10:01.740 William Cheng: Okay. So in our case, we don't really know whether it's going to work on. So what we have to do is that we have actually simulated to see that actually will work. 76 00:10:02.040 --> 00:10:07.350 William Cheng: Okay, if it turns out that there's a scheduled okay if we actually figure out exactly when do wrong with job. 77 00:10:07.710 --> 00:10:18.660 William Cheng: Okay, and we can, we need to check whether every deadline is that deadline is not if it turns out we can do that, then remodel has scheduled to work. Okay, so we're going to see an example of how to actually do that right 78 00:10:20.670 --> 00:10:29.760 William Cheng: So in this case, we have three jobs over here. All of them are periodic jobs right job number one over here. What is ti over here, right here, one over here equals to the 79 00:10:30.270 --> 00:10:35.580 William Cheng: Movie or 0.5 but it doesn't really matter if it's, you know, our or minutes or seconds or something like that. 80 00:10:35.910 --> 00:10:45.090 William Cheng: So we're going to assume that this is, you know, second right so T one over here is going to be 0.5 seconds and then what is p one p one over here is going to be the period equal to 1.5 81 00:10:46.410 --> 00:10:53.220 William Cheng: Guys, in this case, he went over P one is going to be equal to one over three. So this is the job that I just talked about, if this is job you 82 00:10:53.640 --> 00:11:02.520 William Cheng: If this is the only job that you run, you will eat out one third of your CPU that job number to over here again T TO IS EQUAL TO 0.5. What about p two. 83 00:11:03.030 --> 00:11:14.220 William Cheng: P two over here, this job repeat every four seconds. So, p equals two for teacher over P two is going to be close to zero point 40 bye bye bye bye bye for is going to be able to one over eight 84 00:11:14.700 --> 00:11:25.110 William Cheng: Okay, so this one, you know, one eighth of the CPU okay job number three t three over here equals two, one seconds and then p three is going to be equal to what it repeats every 2.5 seconds. 85 00:11:25.590 --> 00:11:33.450 William Cheng: So the utilization of job number three is going to be equal to one over 2.5 Or equal equal to two divided by five equal to 40% 86 00:11:34.050 --> 00:11:41.940 William Cheng: Of so again if you only run down over three, you gonna eat up 40% of CPU. What if you run all the jobs over here. I think I skipped past one slide over here, right, if you 87 00:11:42.660 --> 00:11:52.560 William Cheng: If you add up all the utilization over here we're going to end up with job number one is gonna be one over three job number two is going to be equal to one, one over eight right job number three over here, it's gonna be to over five 88 00:11:52.980 --> 00:12:04.380 William Cheng: You can see that the denominator over here. They're all relatively prime with each other. So, therefore, to get the common denominator. I just multiply the denominators together three times as 2424 times five, zero to 120 89 00:12:04.620 --> 00:12:09.630 William Cheng: What are the numerator right five times for able to add plus three times five or 15 90 00:12:09.960 --> 00:12:22.710 William Cheng: Plus two times three times a week or 240 a this number is going to be 103 over 120. I mean, clearly this number is less than one, what is this number greater than, less than, you know, less than or equal to that equation. 91 00:12:23.580 --> 00:12:35.970 William Cheng: So in this case, n equal to three, because we have three jobs. So we come to this equation over here, what n equal to three. This equation is 0.7798 is this number bigger or smaller than 0.7798 92 00:12:36.510 --> 00:12:51.330 William Cheng: Okay. I mean, this number clearly is bigger than 0.8 right because, you know, because what a 0.0 point 896 over 120. So this number. The numerator is 103 so this is bigger than zero point A and clearly 0.8 is bigger than 0.7798 93 00:12:52.470 --> 00:13:02.190 William Cheng: Okay, so therefore the sum over here is going to be not less than this equation. So in this case we don't know whether a mountain, how to schedule is guaranteed to work on our. So in this case, we have the simulator that 94 00:13:03.630 --> 00:13:13.920 William Cheng: Alright, so we try to simulate it. Right. So yeah, the simulation is that we need to run rate monitor scheduler is preemptive and also it's based on the party and the party is proportional to one over the period. 95 00:13:14.220 --> 00:13:21.840 William Cheng: Okay, so yeah, p one over here is equal to 1.5 right P two over here equals two, four and P three equals two 2.5 96 00:13:22.470 --> 00:13:32.970 William Cheng: So in this case, you know, who's going to be the highest priority, the highest priority is going to be the one with the smallest period we have 1.5 we have four we have 2.5 so therefore job number one will be the highest party. 97 00:13:33.480 --> 00:13:42.930 William Cheng: What about job number to over here, this is the one with the longest period. So this one is going to be with the with the last party and john number Sylvia is going to be in the middle. So this one is going to be medium priority. 98 00:13:44.220 --> 00:13:55.140 William Cheng: Okay, so therefore that's how you know that's going to be our remote scheduler. We're going to assign these three party. And again, we're using priority scheduling. I'm going to claim that this is going to be the schedule that we're going to test with 99 00:13:56.310 --> 00:14:02.100 William Cheng: That we're going to schedule all these jobs so job one is going to start running on time you go to zero job to is going to start running good time to zero. 100 00:14:02.310 --> 00:14:07.980 William Cheng: And job three is also going to start time you go to zero. So what I'm trying to simulate this to see if all the deadlines can be 101 00:14:08.310 --> 00:14:17.940 William Cheng: Can be can be satisfied if they can. But then, then we have a solution for you. Okay. If we don't want. What else do we do right so it's a little girl when you try something else. It doesn't work. Yeah. 102 00:14:18.510 --> 00:14:26.730 William Cheng: Alright, so let's schedule all these jobs can run at this time. And then we're going to remember job number one is highest priority job number two as a medium party and job number three. 103 00:14:27.720 --> 00:14:30.690 William Cheng: Or number two, as most party. And number three, has a medium priority. 104 00:14:31.170 --> 00:14:39.480 William Cheng: OK, so I'm going to claim that job number one whenever they want to run inside a CPU, they get earnings. That is the view because they are the highest party. Nobody can preempt them. 105 00:14:39.900 --> 00:14:48.780 William Cheng: Okay. So, therefore, if I schedule job number one to run inside the CPU at this time. This will be the exact time they will run inside a CPU. Right, so therefore the schedule for john number one's gonna look like this. 106 00:14:49.710 --> 00:14:53.820 William Cheng: That this will be the time job number one's gonna be running out of CPU. Okay. 107 00:14:54.420 --> 00:15:04.410 William Cheng: All right, what about job number, the second highest part each job is gonna be job number three. Right. So if we schedule job number three over here at tenable zero. When is it gonna start running 108 00:15:04.740 --> 00:15:09.540 William Cheng: Right, because I can go to zero job number one is running out of CPU. So Job number three has the ways that around you. 109 00:15:09.750 --> 00:15:16.590 William Cheng: When job number one is done then job number three over here will be executing for one second. Right. So there was three is going to fill up this gap right here. 110 00:15:16.980 --> 00:15:24.330 William Cheng: So in a sense, Job number three over here is going to be delayed by half a second, and that is in a room for one second and then is going to finish and then job, no one's gonna want again. 111 00:15:25.140 --> 00:15:30.360 William Cheng: Okay, so the first time when you bought some rosemary over here is going to run by delay half a second is going to meet a deadline. 112 00:15:31.200 --> 00:15:35.280 William Cheng: Well, we can actually know exactly what is going to finish. When I finished right here at time you go to 1.5 113 00:15:35.550 --> 00:15:42.900 William Cheng: The deadline over here is going to be three right because job number three over here has to finish executing. By the time, next time john number three arrives. 114 00:15:43.500 --> 00:15:51.180 William Cheng: Okay. So, therefore, you know, the deadline is right here. Right. So in this case, Job number to finish right here is actually 111 second ahead of the deadline. 115 00:15:51.870 --> 00:15:57.870 William Cheng: So therefore, this actually works out pretty well. Then the second time you write down. Number three over here. It's going to start a time you go to 2.5 116 00:15:58.110 --> 00:16:05.190 William Cheng: You're going to run for half a second. And now job number one, the higher party Java right so now you need to you know move john number three it back into the run queue. 117 00:16:05.340 --> 00:16:15.720 William Cheng: You're going to save the contacts and then you run job number one job number one finish. You're going to restore the content, we've done over three. So in that case, they have half a more seconds to go. So therefore, he will finish actually tell people before 118 00:16:16.530 --> 00:16:23.520 William Cheng: So therefore job number. So he's gonna stab at me to start having those 2.5 and he will finish it time equal to four over here. Did this job me, then I 119 00:16:23.880 --> 00:16:29.190 William Cheng: Buy again that meet the deadline is right here. So again it beat the deadline by one second. So therefore, in this case, there's no problem. 120 00:16:29.580 --> 00:16:31.440 William Cheng: Next time we write down. Number three over here. 121 00:16:31.770 --> 00:16:38.520 William Cheng: Actually turns out. Nobody else running out of CPU. We don't really care about the most part of the job because, you know, whenever you know as long as the highest quality jobs. 122 00:16:38.790 --> 00:16:44.550 William Cheng: In the CPU the medium party job is actually the king. Right. So whenever it needs to run. Is that a CPU, because we're running out of CPU. 123 00:16:44.910 --> 00:16:49.170 William Cheng: Now, so therefore this time you'll run out of CPU right here and this clearly this one me that that right 124 00:16:50.100 --> 00:16:56.010 William Cheng: There and then next one's going to run, you know, run a time go to seven 7.5 and now you notice that 125 00:16:56.370 --> 00:17:07.110 William Cheng: You know, Job number three over here. Start at exactly the same time is job number one. So we know that from this point on the pattern that we see at the beginning 7.5 seconds over here. This pattern is going to repeat over and over and over again. 126 00:17:08.850 --> 00:17:18.300 William Cheng: Okay, so again the reason over here is that job number three. The period. So as a P3 over here you go to 2.5 right and then you know p one over here is to go to 1.5 okay 127 00:17:18.660 --> 00:17:22.590 William Cheng: 7.5 is actually a common multipliers I time to go to 7.5 128 00:17:22.800 --> 00:17:32.220 William Cheng: The same, you know, there's the scam. Say, I said, You're gonna repeat over and over again. So if we know that job number one and number two, all their jobs going to satisfy their deadline during this first 7.5 seconds. 129 00:17:32.460 --> 00:17:34.830 William Cheng: Then for this point now all of them will satisfy the same deadline. 130 00:17:35.580 --> 00:17:45.510 William Cheng: Okay, so they have what we don't have to simulate anymore. We just, you know, cut it off right here. And then we know we declare that if you only run job number one job number three, then all the deadline for john number three, there will be satisfied. 131 00:17:46.920 --> 00:17:58.080 William Cheng: So therefore, the sketch is gonna look like this. Right. And then all jobs over here are happy. And now we need to look at job number two, because that's the one with the lowest party. It will only get to run inside a CPU when the other job and our president 132 00:17:58.470 --> 00:18:02.340 William Cheng: Well, so if you schedule this job. And have you go to zero. When is it gonna start running 133 00:18:02.610 --> 00:18:10.830 William Cheng: Right. So again, all this time over here the CP is busy so so this job is going to get run right here. Right. So there's always going to get delayed by one and a half second over here. 134 00:18:11.190 --> 00:18:18.330 William Cheng: They meet the deadline, right, the deadlines it right here. So again, there's plenty of time for us to actually finish. So we will meet again on the second night when job number two. 135 00:18:18.660 --> 00:18:26.100 William Cheng: Yes, are running over here now. So it's going to run at this time time before over here, there's a gap right here. So we have we run number two. Again, way ahead of schedule. 136 00:18:26.730 --> 00:18:31.050 William Cheng: Next time, when you've got a job number two will be a, what is it gonna run right. Actually, he's gonna run right here. 137 00:18:31.470 --> 00:18:34.650 William Cheng: But, you know, are we going to see the same patterns going to repeat over and over again. 138 00:18:34.920 --> 00:18:41.580 William Cheng: What the answer is no, because in order for the CD repeat job number two has to start exactly the same time that job number one and three. 139 00:18:41.790 --> 00:18:52.620 William Cheng: Okay, so what is not going to happen. Right. We know that job number one or three every, you know, every 7.5 seconds. They're gonna they're gonna start at the same time job number two has appeared or for 140 00:18:53.640 --> 00:19:00.000 William Cheng: That. So in that case, if you multiply these two number, it's going to be equal to 30 seconds right so if you simulate after surgery. Second, 141 00:19:00.240 --> 00:19:06.510 William Cheng: That we know that at time you go to 30 seconds or job number one, two, and three. They will, they will start exploring all exactly the same time. 142 00:19:07.410 --> 00:19:15.990 William Cheng: So in this case, you know, we shouldn't stop. And over here, we're going to continue over here and we buki similarity. We're going to see that I'm I don't have any room over here. 143 00:19:16.500 --> 00:19:24.600 William Cheng: So you can actually do this. This is yourself okay if you simulate all the way to go to city, and he will see that job number two, they will always satisfied the requirement. 144 00:19:25.500 --> 00:19:35.130 William Cheng: Okay. So in this case, we're pretty lucky because we we add up all the three utilize it over here, even though it's bigger than that fancy equation, right. And then also, it's also less than one. 145 00:19:35.520 --> 00:19:40.140 William Cheng: So in that case, we have to simulate those and we found out that if we simulate it all the way to 30 seconds. 146 00:19:40.320 --> 00:19:50.760 William Cheng: And we found out that all the job will always meet a deadline and then from this point on the pattern is going to repeat over and over again. So we know that even if we simulate your time good infinity all the job will satisfy the deadlines. 147 00:19:51.930 --> 00:20:03.720 William Cheng: Okay, so in this case the Raimondo schedule is going to succeed. Right. So job to over here, we'll run it this time. And I didn't finish my simulation. If you keep doing this up to 30 seconds, you will see that you know they they will succeed. Yeah. 148 00:20:04.650 --> 00:20:09.150 William Cheng: Oh, I wonder if I had another job over here. Okay, so I'm going to add job number four. 149 00:20:09.540 --> 00:20:20.430 William Cheng: Number four, we hear is going to even have lower priority because in this case to 134 is going to be equal to 0.5 what is going to be the period right P for is going to be equal to 4.5 seconds. 150 00:20:20.910 --> 00:20:27.120 William Cheng: OK. So again, this is the one with the longest Pirate Party over here. I'm sorry that the longest period. So, this one will be the lowest priority. 151 00:20:27.390 --> 00:20:32.340 William Cheng: Right. If you are, you know, final utilization or job number for this one is going to be equal to one overnight. 152 00:20:33.030 --> 00:20:41.010 William Cheng: Before we have to someone who ization is going to be going to 103 plus 120. And now if we have one over nine to it is going to be exceeding 153 00:20:41.310 --> 00:20:48.720 William Cheng: Is going to be 60 100% guys, okay, you have to add this. We just got to multiply that denominator together over here. We're going to get 154 00:20:48.990 --> 00:21:02.760 William Cheng: You know 1080 at the denominator over here. The numerator is going to be 927 plus one and 20 the numerator is going to be 1047 that novice can be 1080. I mean, clearly this number is less than one. 155 00:21:03.300 --> 00:21:08.640 William Cheng: Okay, is this number is going to be bigger than the equation of course going to be bigger because even when n equal to three is bigger already 156 00:21:08.820 --> 00:21:16.350 William Cheng: Now we add more stuff into the equation is going to get bigger. And then the equations of here, Kate is smaller. So therefore, we know that we have to simulate us 157 00:21:17.190 --> 00:21:26.670 William Cheng: There. So when we start simulating this right job. Number one, two, and three, they again they have exactly the same schedule and then we already know that all job number one, two, and three. They will all be to that line. 158 00:21:27.060 --> 00:21:36.240 William Cheng: Okay. Job number four has the longest period. So I have the lowest party so only gets around when the CPU is available. So if you get a job number four we here at time equals zero, what's going to happen. 159 00:21:36.540 --> 00:21:44.850 William Cheng: Is going to run at this time right didn't meet the deadline, know that deadline is actually right here. So we know that in this case job number four doesn't really work out. 160 00:21:46.260 --> 00:21:50.820 William Cheng: Okay, so in this case right this number over here is less than one, but we seeing, you know, two different cases over here. 161 00:21:50.970 --> 00:22:00.570 William Cheng: One is that when this number is less than one, but bigger than equation very Monaco scheduled actually work. So in this case, you know, it's less than one and also is bigger than the equation. So this case doesn't work. 162 00:22:01.500 --> 00:22:02.520 William Cheng: So this is what do you do 163 00:22:03.060 --> 00:22:11.460 William Cheng: Well, you can, you cannot do say that, well, maybe. Well, actually, we need to shift job number four rounds to see, but actually work right because we, I started having to go to zero. Why do I started talking to go to zero. 164 00:22:11.730 --> 00:22:25.410 William Cheng: Okay, maybe I can actually do it all these job will be up by three seconds. So this guy's four star right here. And the next time you will run. Next time you write it will be, you know, 4.5 seconds later, so we can you run right here. Right. So this is the job actually meet the deadline. 165 00:22:26.610 --> 00:22:31.290 William Cheng: Okay, so this because, again, when you just send me there for a long time. And then, as it turns out that if you, you know, 166 00:22:31.620 --> 00:22:44.790 William Cheng: This particular example know model when when you start job number four, at some point, you know, one of them is not going to meet a deadline. Okay. So Job number 123 always meet a deadline john before over here if it turns out the schedule is like this, it will not meet 167 00:22:46.050 --> 00:22:55.350 William Cheng: That but they used a while, maybe not. I'm not done yet. Over here. Maybe I should ship the other job of your job, one, two, and three. So you can now see that why scheduling is a very, very difficult problem in the, you know, 168 00:22:56.310 --> 00:23:05.220 William Cheng: The real time says that he goes I eventually I need to consider all different kinds of time shift. And then, and then in that case I will need to try, you know, all kinds of simulation to see if I can 169 00:23:06.030 --> 00:23:08.220 William Cheng: Actually come up with a schedule that will meet all that line. 170 00:23:08.730 --> 00:23:15.450 William Cheng: Okay. After I perform all the time shift, then in that case, I can, I can actually give up. I said, under no condition and this is going to work. And then eventually I give up. 171 00:23:16.230 --> 00:23:25.860 William Cheng: Okay, so you can also see that why in a multi CPU case, the scheduling for real time system is going to be empty. There's going to be empty hard problem. You know, because there are too many different combinations to try 172 00:23:27.120 --> 00:23:31.860 William Cheng: All right. So in this case, we're going to try a different scheduling algorithm, we can actually try the Earliest Deadline First will be here. 173 00:23:32.070 --> 00:23:43.680 William Cheng: On this periodic Tesco here to actually see by work right because that's how should a much, much easier approach to go other than trying to all different kinds of combination ob gyn and yeah, we don't really know if it's if it's if it's gonna work. Yeah. 174 00:23:45.240 --> 00:23:47.460 William Cheng: So we're going to try to enforce over here it right so 175 00:23:48.000 --> 00:23:56.460 William Cheng: Verse over here is that at any instance of time over here. Right, we're going to actually look at the job and then look at a job in the run queue. Find out which one has the Earliest Deadline 176 00:23:56.850 --> 00:24:01.320 William Cheng: Okay. And that will be the job. We're gonna run inside of CPU and now we're going to use a non preemptive scheduling. 177 00:24:01.980 --> 00:24:02.820 William Cheng: Then once we see 178 00:24:03.270 --> 00:24:06.300 William Cheng: This job instead of CPU over here is going to run until completion. 179 00:24:06.480 --> 00:24:15.330 William Cheng: And next time when the CPU CPUs available. We're going to see what jobs that are. Thank you again, we're going to look at the one and find out which one has the earliest and I and that will be the Java runtime CPU. 180 00:24:15.960 --> 00:24:26.280 William Cheng: Okay, again, it's a very simple algorithm and you know is easy to implement. Again, we like scheduler that are really, really, really simple and happy no good execution complexity. Yeah. 181 00:24:28.230 --> 00:24:30.720 William Cheng: So, so let's actually similar this to see earliest and I'm 182 00:24:31.830 --> 00:24:39.120 William Cheng: The first algorithm will actually work. And we know that it's actually pretty good algorithm because under certain conditions. This is actually the best you can do is the optimal algorithm. 183 00:24:39.570 --> 00:24:47.040 William Cheng: Then, so under real time scheduling and can try to see if it works. There are at time you go to zero over here, I see do you become available. Who do we run 184 00:24:47.340 --> 00:24:56.820 William Cheng: Okay, we have four jobs arriving simultaneously at the wrong Q job number one the deadline is right here. Job number two the deadline is right here right I'm ready to run before the next time they appear 185 00:24:57.060 --> 00:25:04.320 William Cheng: My job as soon as that is your job number for that is right here. So who's going to be the winner, the winner is going to be at one with the earliest Li. So there was going to be this one. 186 00:25:04.590 --> 00:25:13.290 William Cheng: I'm going to color this arrow read to show you what was the winner. So in this case, Job number one is the winner. So I time you go to zero. I'm gonna run run job number one over here. 187 00:25:13.590 --> 00:25:23.880 William Cheng: Instead of CPU and again. Now, there's no party, the only party is the deadline. Okay, so therefore once job number. While we're here, you schedule them for instead of CPU, nobody will be able to pump it off. 188 00:25:24.780 --> 00:25:34.500 William Cheng: There was a time you go to 0.5 over here. Now the CPU become available. Who do we run that right at time equals 0.5 who is loving that around. Q. 189 00:25:35.190 --> 00:25:43.260 William Cheng: One job number one doesn't appear until 1.5 seconds. So at time to go to 0.5 there's only going to be three job. So again, I mean you got about this job. 190 00:25:43.800 --> 00:25:52.080 William Cheng: So at time equals to 0.5 only job number two and three and four there instead of wonky. So in this case, I have to look at your deadline and ignore the one inch. 191 00:25:52.410 --> 00:25:55.680 William Cheng: Job number one because he just left the system and a new one hasn't arrived yet. 192 00:25:56.100 --> 00:26:06.450 William Cheng: Then so Tommy, what is a 0.5 is three deadlines over here by so in this case clearly job number three is the winner over here I'm enjoy. Right. Oh, yeah. So I'm going to run job number three right here. 193 00:26:07.110 --> 00:26:10.260 William Cheng: Okay, so when it finishes over here is going to be time you go to 1.5 194 00:26:11.250 --> 00:26:16.470 William Cheng: Well, that's a better way. Job number one over here clearly meet the deadline job number three. Oh, we give me the deadline right over here. 195 00:26:17.010 --> 00:26:22.830 William Cheng: So far our earliest time for the schedule look exactly the same as the way Monaco scheduled. Okay. 196 00:26:23.340 --> 00:26:32.250 William Cheng: Tommy, go to 1.5 job number one arrives over also a. Right, right. The new job. Number one, I will be here. So we need to take them into account. Now we're going to end up with three deadlines over here. 197 00:26:32.460 --> 00:26:37.890 William Cheng: One, two, and four over here clearly one is the winner. So we're going to run job number one over here. 198 00:26:38.400 --> 00:26:43.980 William Cheng: At one point plan. So again, this schedule is going to be exactly the same as a reminder scheduler. 199 00:26:44.580 --> 00:26:47.490 William Cheng: Time equal to two, no new job has arrived. We're gonna look at to 200 00:26:47.760 --> 00:26:58.500 William Cheng: That line over here. What is number two. What is number four. Number two is going to be the winner. So therefore, we're going to run to inside the CP over here again the schedule look exactly the same as the way mom has scheduler. 201 00:26:59.280 --> 00:27:07.590 William Cheng: Time you go to 2.5 job number three arise over here. So again, we need to look at that deadline as well. Right. So now john number three is here. Job number four here server deadline. 202 00:27:07.770 --> 00:27:15.840 William Cheng: So in this case john number four is actually the winner so. So in this case, you know, Job number four is going to be the winner. So right here we need to run around job number four. 203 00:27:16.800 --> 00:27:22.770 William Cheng: Now, this will be the first time the rain monotonic scheduler you disagree with, or this July 1 204 00:27:23.580 --> 00:27:25.080 William Cheng: Okay, so who is making the right decision. 205 00:27:25.500 --> 00:27:31.290 William Cheng: Well, I mean, of course, we know that remark on scheduling made a wrong decision. That's why in the end they cannot run all these for jobs right 206 00:27:31.440 --> 00:27:39.810 William Cheng: So in this case, you know, as it turns out that Robin is that job number three over here in me to stay alive. One second ahead of schedule so we can actually delete I've ever seen by a little more 207 00:27:40.320 --> 00:27:50.880 William Cheng: Okay, there's no reason we have to run out. Number three, right here. Okay. So as it turns out, you know, by using the Earliest Deadline First scheduling for them. They actually, you know, sort of discovered this all by itself. 208 00:27:51.510 --> 00:27:58.950 William Cheng: Okay, without using, you know, so you know look at prediction of when you know that that has the deadline for that job is the watch it says, you know, maybe run as the right time Raja 209 00:27:59.670 --> 00:28:12.720 William Cheng: Raja number four over here because that will be the wild with earliest li, li. So therefore, in this case, the early July 1 over here. We're rod rod job number four right here and this one will meet a deadline. Okay. As it turns out, this one is actually the right decision then 210 00:28:13.980 --> 00:28:21.060 William Cheng: Time equals three over here. Job number one. Also, right, we need to take that into account over here. Now, we end up with two deadlines over here. One is 1123 211 00:28:21.360 --> 00:28:29.520 William Cheng: Clearly, one is the winner. So we're going to run one right here. So we're going to further and further delay job number three over here to start at a later time over yet now. 212 00:28:30.180 --> 00:28:39.510 William Cheng: at time equals 3.5 no new job isn't right. And now the only job is to run Q job number three. So now we actually we're going to run job number three over here for entire one second. 213 00:28:40.440 --> 00:28:47.940 William Cheng: Okay, so it will be looking like this right now right john drama series. The only ones that run queue. So there will be the winner. So we actually run at this time. 214 00:28:48.720 --> 00:28:55.800 William Cheng: Okay, so remember that job number to arrive. Well, we had time to go to for but again we are, we're not doing the scheduling over here. So therefore john numbers we 215 00:28:56.250 --> 00:29:04.050 William Cheng: Continue to run inside the CPU and also if you look at it, airline OVER HERE, JOHN Masuda lines over here. Job number two the demos over here. So again, JOHN i'm jewish should be 216 00:29:04.890 --> 00:29:09.900 William Cheng: Even if you're doing preemptive scheduling job number three. She's still continued running out of CPU. Yeah. 217 00:29:10.710 --> 00:29:17.790 William Cheng: All right, so number three is running over here at time you go to 4.5 when it finishes job number two job number one job number four. They all arrive over here. 218 00:29:17.970 --> 00:29:23.730 William Cheng: We're going to end up with three deadlines here. Number one over here is going to be the winner. So I'm going to schedule job number one right here. 219 00:29:24.780 --> 00:29:29.970 William Cheng: Okay, so, so, so, so again I will run out of CPU right here and this one will meet the deadline over here. 220 00:29:30.810 --> 00:29:37.410 William Cheng: And, you know, at time equals to five over here. Job number three also arrived. When you look at three deadlines over here. 221 00:29:37.620 --> 00:29:45.900 William Cheng: Number three over here is going to be the winner. So, this guys want to run. Number three, inside the CP over here so you can see that this job number to actually get the lake quite a bit. 222 00:29:46.530 --> 00:29:58.740 William Cheng: OK. So again, if we look at the original case over here, this job was supposed to run at this time. So again, you know, there's a lot of times before it's dead I so therefore we can actually, you know, continue to delay this job until the time when it's, you know, 223 00:29:59.160 --> 00:30:10.530 William Cheng: Until when it's time to run job too because we can actually see the earliest that I'm for is actually pretty clever. The watch the sort of run the right job. You know, first the job as a leader delegate that why should run at a later time, they're 224 00:30:11.460 --> 00:30:15.690 William Cheng: All right, so number three is going to be running right here at time people to save job number one arrive again. 225 00:30:15.990 --> 00:30:21.510 William Cheng: When you look at around to be here and this one is going to be the winner. So we're going to run inside a CPU for jumping on one over here. 226 00:30:21.690 --> 00:30:29.820 William Cheng: We still haven't run job to yet right at time equals to 6.5 over here, no new job has arrived. The only jobs left or two and four over here. 227 00:30:30.000 --> 00:30:39.090 William Cheng: So this guy's to will be the winner. So we're going to run to inside of CPU, because you can see that this job over here is delayed by quite a few seconds over here, you know, to, to be run at this time. 228 00:30:39.660 --> 00:30:44.010 William Cheng: Then it time equal to seven over here. Again, no new jobs arrived, we only have one job inside of 229 00:30:44.250 --> 00:30:54.300 William Cheng: You and just want a job number four. So in this case, we're going to actually run job number four, right here, this will be the winner on job number four. So this job number four actually gets to run over here and again a piece of that line over here. 230 00:30:55.320 --> 00:31:05.700 William Cheng: Okay, so we can actually see that you know for the rain monotonic scheduler, you can actually run these job number four we here by squeezing them into our schedule. So in the end, everybody needed a deadline and then we still have, you know, 231 00:31:07.140 --> 00:31:09.480 William Cheng: Plenty of time left to do everything else. 232 00:31:10.770 --> 00:31:19.410 William Cheng: Alright, so, so again you see you can you can you see this case number two is it gets shipped. And number three, get shifted so this way, they create room to actually run number four. 233 00:31:19.710 --> 00:31:21.990 William Cheng: They even though the number four. Here is the 234 00:31:22.320 --> 00:31:33.900 William Cheng: Is the one with the lowest period, but at some point it becomes it becomes urgent, run, run, run. Job number four and using the Earliest Deadline for example them. They actually sort of figure out the right time to run around job number four. Yeah. 235 00:31:35.160 --> 00:31:41.820 William Cheng: All right we're going continue to simulate over here at time equal to 7.5 job number one in three arrived. While we're here, so again I'm going to switch 236 00:31:42.240 --> 00:31:52.800 William Cheng: When it's just going to run through the side over here so you can see that if we continue to do the simulation over here. All the job over here, they will satisfy you know they do it the data whether it 237 00:31:53.610 --> 00:32:01.080 William Cheng: Satisfy you know their deadline, but that's okay. How long do I have to simulate right, I have to simulate until all these for jobs are running at exactly the same time. 238 00:32:01.470 --> 00:32:09.540 William Cheng: And so, again, the cycle that we started before 7.5 times four is going to be able to 30 and now the last one over here the cycle is equal to 4.5 239 00:32:09.930 --> 00:32:18.270 William Cheng: So in this case, what's going to be the, the common multiplier. Okay, so a time you go to 6060 seconds over here, then in that case will be a common mode. 240 00:32:20.400 --> 00:32:30.300 William Cheng: Okay, I guess you know 4.75 over here. Yeah, so I time to go to 60 then in that case they're you know they're they're all synchronize the all the, all these four jobs are running exactly the same time. 241 00:32:30.750 --> 00:32:37.080 William Cheng: Well, so if we continue to simulate this one using the earliest LM first that we know that triangle. The 60 will see that all the jobs over here. 242 00:32:37.350 --> 00:32:48.180 William Cheng: All the deadline will be satisfied. Okay. So this guy is again the earliest align first turns out to be a pretty good scheduling algorithm, we can actually use that to schedule your time job. So in this case, we'll figure out all the schedule over here. 243 00:32:48.750 --> 00:32:55.350 William Cheng: Okay, bye, bye, bye, bye, bye, bye, simulating them. So, so in this case we know that for every job when are they supposed to run inside a CPU. 244 00:32:56.040 --> 00:33:05.010 William Cheng: Okay, and then we can declare victory to say that. Yeah, you know, using this particular CPU is these are the four jobs that you that you need to run when you add, I will do you as issue, even though it's very close to one. 245 00:33:05.220 --> 00:33:14.340 William Cheng: We can use the earliest then I'm first to figure out exactly what the schedule is and India, we're going to actually show you, you're describing the schedule that will satisfy all the constraints. Yeah. 246 00:33:16.800 --> 00:33:16.980 William Cheng: Oh, 247 00:33:18.060 --> 00:33:21.810 William Cheng: The textbook also talk about this to face problem. You know, so 248 00:33:22.020 --> 00:33:31.560 William Cheng: By running the job at a later time over here. It's called face shifting right. So in the beginning, over here, the example that we saw we hear all the job they all run in phase, they all start exactly the same time. 249 00:33:31.950 --> 00:33:39.480 William Cheng: We also got the scheduling harm or difficult because if it doesn't work out what you need to do is you need just try to you know shift all the phases. Both have all these jobs over here. 250 00:33:39.690 --> 00:33:47.670 William Cheng: By generating all possible combination over here. So in this case, we can actually shift them by half a second. Why don't we also shift them by, you know, quarter of a second. 251 00:33:48.120 --> 00:33:50.160 William Cheng: Right. Is that going to work. They're going to work better. 252 00:33:50.550 --> 00:33:59.010 William Cheng: I'm not really sure. OK. So again, you need to try all possible combination on who you at some point you convinced that none of the schedule was or eventually going to figure out a schedule that will work. 253 00:33:59.760 --> 00:34:09.960 William Cheng: Okay, so yeah, we're not going to talk about it. Just want you to be aware that, you know, you can actually make the point, you know, you should you should explore a little more by doing face shifting in all the jobs, you know, to find it. 254 00:34:11.010 --> 00:34:16.860 William Cheng: Find another schedule that that might work. Okay. All right. Again, there you know all these things were skipping 255 00:34:18.000 --> 00:34:26.160 William Cheng: A ok and then there are some additional implementation issue in Chapter Chapter five will sort of talk about when it comes to scheduling one is our 256 00:34:26.670 --> 00:34:32.460 William Cheng: You know, what is our old friend priority inversion. We saw that in chapter five. There's some party version. 257 00:34:32.670 --> 00:34:37.770 William Cheng: Remember we talked about this user threat rather use your sweat over here and then there Colonel Suez over here. 258 00:34:38.010 --> 00:34:45.420 William Cheng: By the user. So I might be how high priority low priority inside the Colonel. There's also high priority and low priority when they come inside the Colonel. 259 00:34:45.660 --> 00:34:52.110 William Cheng: The high parties there might be a runny and a low party kernels that again. Why would the contract, you have no party. I have already threads. 260 00:34:52.470 --> 00:35:02.700 William Cheng: When scheduling. If we, you know, the, the, I guess the way we saw the multi level feedback you right he's the motivation level feedback to the party is going to change. So it is possible that these two 261 00:35:03.120 --> 00:35:07.800 William Cheng: These two threads. Originally, they are the same priority, but after you run for a while, actually have different party. 262 00:35:08.730 --> 00:35:13.260 William Cheng: Okay. And also, you know, different operating system. They have to avoid to implement them. So when they are studying certainly use 263 00:35:13.620 --> 00:35:22.320 William Cheng: Dynamic party. It is possible. He's not a colonel, you're going to also end up with. Right. What about in the user space or the piece where I live. We allow you to set different priority for the user. 264 00:35:23.130 --> 00:35:25.800 William Cheng: Flow for the user. And that's why you can enter whatever party. 265 00:35:26.580 --> 00:35:33.540 William Cheng: Guy, so therefore they become possible that the high party so via when they come into the kernel, you will be scheduled on a low parties where the law party. So we here. 266 00:35:33.690 --> 00:35:39.090 William Cheng: Will be scheduling a higher party thread. So in this case, when to to as companies that Colonel simultaneously. 267 00:35:39.270 --> 00:35:44.400 William Cheng: Which one is going to return to the user space verse right so in this case what a higher party. So I was going to return to the user space. 268 00:35:44.580 --> 00:35:51.900 William Cheng: And now the application programmers can be very upset. It says that this one is a lower priority. So I expected when it goes into the kernel. Well, he should return second 269 00:35:52.440 --> 00:35:59.970 William Cheng: Okay, so the higher part is throughout ovulation return for us. But again, you know, when you go from the user space to this kernel. You don't communicate, you're going to end up with this problem. 270 00:36:00.300 --> 00:36:04.260 William Cheng: Right so so again in chapter five, the solution that we started the schedule activation model. 271 00:36:04.590 --> 00:36:13.800 William Cheng: Okay, so now we're going to take a look at a slightly different party version problem there. So in this party in version problem all these threads that would be all users were and there could be all kind of threat. Yeah. 272 00:36:14.640 --> 00:36:20.550 William Cheng: So, so let's take a look at these he adds up over here. We're going to have three guys over here that could be all users throw us all kind of that doesn't really matter. 273 00:36:21.180 --> 00:36:27.840 William Cheng: The age has highs parties to IPS medium parties were see has the last party over here. So if you're running 274 00:36:28.290 --> 00:36:37.230 William Cheng: You're running out of CPU when they're sitting in the queue or they are the they will be sitting in different queue, because we are using a sort of a priority or your priority pay a parody based scheduling. 275 00:36:38.160 --> 00:36:49.050 William Cheng: There. So in this example is a little weird slit your throat PSC, there are the one Q Right, but it is actually sitting at a new tech school over here. And as it turns out, the owner of the new types of stress. See 276 00:36:49.770 --> 00:36:57.570 William Cheng: Okay, so by the time he tried to launch the new tax see actually only made has already and now he has no choice but to wait for season releasing new tax. 277 00:36:58.620 --> 00:37:03.600 William Cheng: OK, so now actually see that yes its way over here. See that thread sees actually over here. 278 00:37:04.110 --> 00:37:13.890 William Cheng: You know, it's actually waiting for the, you know, waiting for the CPU to become available. And then b squared over here. See that, you know, the, you know, the scheduler is actually give me the CPU to threat be 279 00:37:15.180 --> 00:37:21.030 William Cheng: Well, so you can actually see that on the wrong field over here. Slide bees that are ranking. So I see the ranking SEBI has hired party that 280 00:37:21.870 --> 00:37:33.450 William Cheng: I see. So therefore Slappy is going to get all the CPU. That was was let's see over here, it's gonna get stuck inside around Q sway over, he has been I'm very impatient and then it says, Hey, your schedule. I think you make a mistake over here. 281 00:37:33.930 --> 00:37:40.290 William Cheng: You know, you need to get a cease to run because I'm very important you know failure is very, very important. So there was a nice run first 282 00:37:41.220 --> 00:37:49.740 William Cheng: Okay, so some people said, I bought this is really not a party emergent problem because the elders waiting for. I see. So, therefore, you know, it's a new text parking problem. 283 00:37:50.010 --> 00:37:58.710 William Cheng: But in the operating system literature. This is actually consider party version problem okay because over here, I see over here. So, so what are you supposed to do. 284 00:37:59.730 --> 00:38:05.580 William Cheng: Okay, I'll be here. So I see over here is inside a monkey. Oh here it doesn't get to run because he's barking at the Serbians higher party. 285 00:38:06.660 --> 00:38:13.800 William Cheng: Okay, so it's almost like the case where you have, you know, so let's say you're a summer intern, you go work for work for a company and your co tell you just a hey you know go 286 00:38:14.040 --> 00:38:23.700 William Cheng: go to Starbucks and give me a cup of coffee. Oh yeah, well, you go to Starbucks over here you see a bunch of middle management or in front of you. They all cut in front of you. They keep ordering copy. So you never get, you get you to order coffee. 287 00:38:24.150 --> 00:38:28.470 William Cheng: Okay, and pretty soon you got to get a phone call on your CEO to say hey CEOs that hey, where's my, you know, 288 00:38:28.980 --> 00:38:34.470 William Cheng: Where's my coffee. He said, Oh, the all these middle management, they keep cutting in front of me. So in this case, what would the CEO. 289 00:38:35.040 --> 00:38:44.820 William Cheng: Or CEO Terry TO GIVE THE CELL PHONE TO TO THE PEOPLE ARE Starbucks and then the seal will talk to the people to start to say, hey, you know that that summer intern over here that summer interns me 290 00:38:45.720 --> 00:38:54.120 William Cheng: Okay. So, therefore, you have to treat a summer intern as me. So therefore, you're going to get bumped into the high priority queue over here. So you need to serve a summer intern before you serve all the middle 291 00:38:54.570 --> 00:39:02.250 William Cheng: Or the middle management people. Okay, so this could work. Is that a real human situation over here, this and also work inside the scheduler. 292 00:39:02.670 --> 00:39:06.930 William Cheng: Okay, so let's go also to the executive, same thing. This is called party inheritance. 293 00:39:07.770 --> 00:39:22.170 William Cheng: That what he is waiting for a resource help. I see. So A is is waiting for, you know, a new tax waiting for me attacks and the new tax help. I see so often is that during that time, we actually we're going to bomb the party of so I see to be the same level as 294 00:39:23.310 --> 00:39:30.990 William Cheng: Well, that's okay. If thread it has higher part in Australia. Australia is waiting for you. I see you, I see is there temporarily raise the party level to be the same as reading 295 00:39:31.500 --> 00:39:41.400 William Cheng: Okay. So, this way we will be able to solve the previous party version problem, right, because to see over here when it gets to run it will run at the highest party. So therefore, in that case, you know, three days. 296 00:39:42.960 --> 00:39:45.630 William Cheng: Three over here with no longer complain that 297 00:39:46.950 --> 00:39:49.110 William Cheng: Oh, so this will solve to solve this particular problem. 298 00:39:49.440 --> 00:39:54.210 William Cheng: So so so good. As I mentioned before, one of the problem with the higher party and Bernie problem is that 299 00:39:54.390 --> 00:40:01.410 William Cheng: When you saw one of the party and version problem you only saw one particular case. And then you can actually construct another case where you have a different kind of party virgin mobile 300 00:40:01.740 --> 00:40:03.600 William Cheng: Okay, so in this case we have three threads. 301 00:40:04.080 --> 00:40:11.250 William Cheng: You. So, so, you know, by using party hurting yourself this people case. And then you can actually constructed. Another case with four threads and then your solution is not going to work. 302 00:40:11.580 --> 00:40:18.030 William Cheng: And then if that you know you find another solution for it. We can construct another case with five threads. And then again, your solution for three threads and forth where 303 00:40:18.240 --> 00:40:27.060 William Cheng: It's not going to be able to work for the case with five threats there. So, even today, you know, people in Albany system calls to conferences, they're still trying to solve the problem party version. 304 00:40:27.360 --> 00:40:35.070 William Cheng: Yeah. So anyways, we're not going to continue to look at the same. We just sort of want you to know that party inversion problems actually very difficult problem to solve. Okay. In general, 305 00:40:36.870 --> 00:40:45.510 William Cheng: All right. Another thing that we need to worry about is that what if you have multiple CPU again every time we deal with multiple CPUs things going to get a little more complicated guy. 306 00:40:46.140 --> 00:40:50.910 William Cheng: So let's take a look at two different solutions. Over here we have multiple CPU. How many wrong, you should you have 307 00:40:52.110 --> 00:41:01.170 William Cheng: Guys. So here are two different solution. Well, I got one over here is out, you have four different CPUs over here, I can choose to have only one queue or I can actually for every CPU. I have a different view. 308 00:41:02.250 --> 00:41:09.630 William Cheng: Okay, why would we go with the first approach over here. Right. Yeah. If you have to study queueing theory right W classes. Well, you know, the w has a classical coding theory. 309 00:41:09.840 --> 00:41:14.760 William Cheng: If you study queueing theory, you will see that this is the one actually give you the best response time 310 00:41:15.360 --> 00:41:18.210 William Cheng: OK. So again, this is why when you go to the bank. 311 00:41:18.480 --> 00:41:22.710 William Cheng: The bank kind of look like this, where every one of these CPU over here. It's going to be a bank teller. 312 00:41:22.890 --> 00:41:30.360 William Cheng: There's only one line you get into one line over here. And then whenever a telus become available. You know what you will do that will say next. And then you actually go into the CPU. 313 00:41:30.840 --> 00:41:37.830 William Cheng: Okay, so by using this particular configuration, you're going to minimize the waiting time for all the job over here inside this one run cute. 314 00:41:38.430 --> 00:41:49.230 William Cheng: Okay, well, what's going to be the downside with this particular approach. Okay. As it turns out that this work great in the human society. It doesn't really work great for the CPU. Yeah, you're going to CPU over here. They actually have caches. 315 00:41:50.100 --> 00:41:56.280 William Cheng: That instead of CPU there caches over here. And also, if you have multiple CPU case, as we mentioned before, there's a one cache to cache. 316 00:41:56.640 --> 00:42:02.640 William Cheng: There's no LTE cash so is in front of the CPU over here. There's also LCD cash in front of all the CPU over here. 317 00:42:03.420 --> 00:42:12.060 William Cheng: But there's a lot, but it's out when you finished running a job is that one of the CPU over here. We're going to establish information inside the Alfie cash over here. So from this point on, 318 00:42:12.300 --> 00:42:20.460 William Cheng: If you you know when this job co sleeping IoT go sleep in inside a meat AX you when it finished sleeping when it comes back into the wrong view. 319 00:42:20.640 --> 00:42:28.080 William Cheng: It will prefer to run inside the same CPU over here because there are states inside the cat over here that will make this thread run faster inside the CPU. 320 00:42:29.070 --> 00:42:36.450 William Cheng: OK, so the fancy term is called cash affinity. Once you start running into one CPU over here you prefer to run inside the same CPU. 321 00:42:37.140 --> 00:42:43.020 William Cheng: Okay, if you run into another CPU over here, you can actually get more cache misses. So therefore, your performance going to be worse. 322 00:42:43.440 --> 00:42:49.740 William Cheng: Okay. So, therefore, to the cash affinity, the right way to do actually is actually for every CPU to have their own queue. So this way you know 323 00:42:49.950 --> 00:42:57.270 William Cheng: You know inside your control blah, you will remember we CPU. They're supposed to use the so this way. When you are finished, you know, visiting your Iowa visiting me tax. 324 00:42:57.510 --> 00:43:04.230 William Cheng: Well, when you are ready to go inside around kill you look at your second job, blah, and then you schedule yourself to the right, you okay so this way. 325 00:43:05.460 --> 00:43:10.200 William Cheng: You actually have that sort of the best you know situation, you know, according to cash affinity 326 00:43:10.650 --> 00:43:15.420 William Cheng: That abundance in this case, what is the downside for the bottom for job here again, there's no free lunch. 327 00:43:15.660 --> 00:43:23.460 William Cheng: When you take the second approach over here. The downside of the second approach over here is that maybe at the beginning, over here, all these CPUs are actually really busy serving job. 328 00:43:23.790 --> 00:43:28.800 William Cheng: There. But what if, after a while, CPU number four we hear all the job over here have exited 329 00:43:29.700 --> 00:43:35.880 William Cheng: That. So, now is this monkey or we or be completely empty or all the other CPUs over here. The rank you are actually pretty for 330 00:43:36.360 --> 00:43:44.010 William Cheng: Okay, so in that case your CPU utilization can only be a best 75% over here because the four CPU is always idle. 331 00:43:44.670 --> 00:43:52.470 William Cheng: Okay, if you're spending a lot of money on these four CPUs and all you can get a 75% of the software or seven 5% of the utilization, you're going to be pretty upset. 332 00:43:53.040 --> 00:44:01.110 William Cheng: Okay. So in this case, what's going to be the solution that so the solutions over here is gonna is gonna be no as load balancing. So you have to balance the load over here. 333 00:44:01.530 --> 00:44:09.570 William Cheng: So maybe one. So you need to sell them at a timer wasn't a while you're talking to will go off and then you look at all the wrong cute over here for all the for the all the foreign food over here. 334 00:44:09.750 --> 00:44:16.440 William Cheng: And you see that if the load over here is about balance if they're not balanced what you do. So you actually reassigned summer job to a different view. 335 00:44:16.980 --> 00:44:22.230 William Cheng: Okay. So for example, let's say that your timer goes off on here and you see that this you know this around, few of us completely empty. 336 00:44:22.410 --> 00:44:30.450 William Cheng: So what you will do is that you will go through the first three two is over here. Take one quarter out of every one of these computer over here and reassign them to see do number four. 337 00:44:30.630 --> 00:44:41.040 William Cheng: By changes that assert control boxes that are they prefer to run inside secret number four and now you move them onto this monkey over here and now the queue line for all these workers can be about the same. So, and so when 338 00:44:41.400 --> 00:44:46.410 William Cheng: You know, when the four CPU start running over here in the beginning is going to be a little slow because, you know, instead of cash over here. 339 00:44:46.620 --> 00:44:51.840 William Cheng: There's gonna be no information all the software but again after you run it for a while, then all these other side's gonna run pretty well. 340 00:44:52.800 --> 00:45:01.740 William Cheng: Okay, so this guy. You need to perform load balancing once in a while, you just said another timer so when the timer goes off. So in that case, you can perform load balancing. So again, there's no free lunch. 341 00:45:03.150 --> 00:45:12.570 William Cheng: So what is. So, there again, they're well known for pretty good you know performance, they again, they will choose something in the middle. And these are solution or as a processor set over here. 342 00:45:12.930 --> 00:45:23.130 William Cheng: So in the example we have four different CPU. They'll watch his career to long queues over here why around Q4 CPU number one and two and one run Q4, see the number three and four. What did they do that. 343 00:45:23.760 --> 00:45:31.140 William Cheng: Okay, so if you do like this, the probability that monkey over here is empty is going to be much smaller than the previous case over here before. Thank you. 344 00:45:31.500 --> 00:45:39.390 William Cheng: Okay, so therefore, in this case, you don't have to do load balancing bear very often. And also, you know, for these two CPU is going to use one cash will be here. So in that case, 345 00:45:39.810 --> 00:45:48.240 William Cheng: The overall performance of the system study better. So again, this is this the best of both worlds in the previous two cases. And that's what's implemented in Solaris, yeah. 346 00:45:51.420 --> 00:46:00.240 William Cheng: So the last part of it. So I should over here, it's a good time to break so we only have the last part of scheduling. What do we need to briefly talked about and also 347 00:46:00.690 --> 00:46:09.840 William Cheng: I guess after that we're going to go back to chapter, chapter three, to look at dynamic Lincoln and loading and that will finish the entire semester. Okay. Alright, so let's take a short break.