 All right, welcome. It's almost reading week. Yay So you'll have some while knowing that you're in engineering probably it will kind of suck But hey, you won't have to go to campus. So that's something So today should be mostly Review so we're going to go over another scheduling question just so we refresh ourselves before we have a Reading week and quizzes and all that stuff and to go over one of the exam questions that were There previously just so you have something to base it off So let's go ahead and take a look So We'll explore we kind of touched on it before we talked about hey We could have priority scheduling, but we could also have dynamically Dynamic priority scheduling where our algorithm can control the priority dynamically change it so that You have you know your IO bound processes get CPU when they need it And then your CPU bound processes get to execute for a long amount of time So you have better throughput and try and balance the best of both worlds and this is one heuristic Do so that you kind of find the IO versus CPU bound Processes so it may also be called feedback scheduling because we are keeping track of how long things execute for and using that to dynamically change the priority and Keep track of what process we should run and where because that's scheduling So We let the algorithm manage the priorities. So we're going to use set time slices and then we're going to measure CPU Usage and then within a time slice there's going to be timer interrupt So there's going to be many timer interrupts within a time slice Where we could change processes if we want to but we let don't use the time slice So those are processes that just need the CPU for a little bit and then pretty much get blocked or go to sleep So you want to have good response time for that. So whenever they're ready. You essentially want to So in this case decrease priority means make it less important So I want the CPU bound ones to be less important I want the IO one bound ones to be more important so that they're scheduled and you get good response time But confusingly we're going to use the opposite numbers So higher priority will mean a lower number, which is kind of what the Linux kernel does So we'll see that so like we just said We're going to pick the lowest number as the highest priority in this case So how it's going to work Is each process gets assigned a priority when they're started say pn where n is the process id number And then we're going to pick the lowest priority to schedule And then if that process decides to yield or block or whatever and gives it up We pick the next process in our queue based off our priority order and we can break ties with arrival order And then if a lower priority Number becomes ready. We scheduled that so if there's a tie where Something of the same priority is already running. We won't bother switching to it But if a higher priority or lower number comes in we'll schedule that immediately So we're going to record how much time each process Executes for and it's time slice. So we'll have timer interrupt So we're essentially just counting the number of timer interrupts that each process is executing for And there'll be more of that than in the time slice So you'll essentially get to play with these numbers, but the end of the time slice you'll update the priority Yep Or we kind of talked about before have multiple queues for each one or we could have one global queue Or we could kind of do a mixture of both where we have that work stealing thing So we talked about it, but you wouldn't have to like write out a full blown answer about that Because it would just take too long So at the end of each time slice So we're going to update the priority of each thread with it's we're going to half its current priority And then add however many Timer interrupts it executed for And then we're going to reset the value of c for all the processes. So the idea here of the highest priority eventually So that is our way to be nice and fair and you can do all sorts of different heuristics But this is probably the simplest one to understand all right so Question on the midterm that they went over is assume all So it was missing a bunch of information where you had to make your own assumptions So one assumption you could make is that hey the initial priority of all the processes is zero in seconds And each time So within a time slice, there's going to be 10 Timer interrupts that you have to keep track of and that you have to make scheduling decisions for So the question asks what's the schedule that would be generated? So If I assume that they're all ready and ready to execute and I get them in arrival x y a b. What should execute first? X so x was the first one there. They all have the same priority in this so I would execute x And based off the question it just executes for 0.1 second So it only executes for one timer interrupt and then it blocks for 0.5 seconds So it would only execute for one timer interrupt and then it blocks So we can't schedule it anymore. So we have to pick a new process. So what should we pick next? Why so we pick y? Because it's the next one in arrival order it executes for 0.1 seconds goes to sleep. Yep Each of these blocks is 0.1. So each of the blocks is a timer interrupt Where we could context switch So the 0.5 seconds will come into play once Like it will add it back to the ready queue and we can schedule it again So it will come back into play, but for now it just executes for 0.1 seconds and then it will take 0.5 seconds. So Whenever we start executing timer interrupt six at like 0.6 seconds, then Process y or x will be ready again So that's what we'll do. So in this case time set time six here That's when x becomes ready but We would After we execute process y it goes to sleep. We have to pick between a and b. So we would pick process a So it executes and whenever x becomes ready We don't switch to x because it has the same priority of what is currently executing So we just keep on merrily executing process a until the end of the time slice And each time slice in this case based off the question is 10 of the timer interrupts So everyone okay with that? As much as we can be Yeah At each time slice and at each time slice that recomputes the priorities So we have to make a decision at the end of each time slice Yeah Yes Yeah, so if x so we'll see an example where x All we have to do is change the initial priority and we'll have that scenario So we'll see an example after this. So this is the first one if we assume everything is zero So yeah x became ready at the end of or at the beginning of time slice six But we didn't switch to it because everything was a nice big tie And then y became ready at 7 but we didn't switch to it because again Everything has the same priority at that point So a would stay there until the end of the time slice, which is 10 of these boxes So every 10 boxes or every 10 timer interrupts we get to recompute the priorities And then that would change our scheduling decision. Yep priority. Yeah Yep Yeah, so process A process will go in it will start executing for All it will try and execute until the end of the time slice Unless something of higher priority is now rentable and then you would switch So in this case at t10 I schedule based off these priorities So a better version of it would be if processes a and b have a priority of six And then x and y have a priority of zero Or they're blocked. So where are we going to schedule? A so there's a tie between a and b a came first. So we'll just