 Good Okay, so Carl got you to the point When we talk about sort of the CPU when we talk about memory we talk about the disk We sort of go through three stages we talk about a little bit about the details of the hardware so you guys And we talk about some of the abstractions that the operating system creates in order to hide some of the unpleasant details of hardware So you guys learned about threads and about how I switch back and forth between them And then at some point we get to talk about policy so how The operating system is responsible for understand how Threads get moved back and forth on the CPU some of the mechanisms that underlie that how the kernel gets control of the system And today we'll talk about how it uses that control Today and tomorrow and Friday how it uses that control to try to make the best use of system resources When it has to choose which thread has to run so this is something called thread scheduling we'll sort of set the stage data by talking about some of The goals on inner interactive systems, so what do you guys expect your computer to do? What would be some of the things that you would notice if the scheduling that your computer was doing really broke down really got bad And then on Wednesday we'll talk about some scheduling algorithms And then on Friday we'll do a case study of sort of a more modern scheduling algorithm talk about that. All right Three cheers for Carl. Let's give Carl a round of applause You know, I don't I don't think the right question is was Carl awesome The question is how awesome was Carl right because I can I can imagine that was fantastic According to him. He has some of his own verbal tics to work on just like me, so On that I don't know how many times he said that but I'll go back on the video and count But yeah, I really appreciate the Carl lectured assignment to checkpoint So Scott and I were you know that the core staff were pretty happy with the numbers for assignment 2.1 How many people didn't submit assignment 2.1, but tried to submit assignment 2.1? Okay, a couple of people right Yeah, I mean, I hope that it's at least got people moving right even if you didn't manage to get the 20 points Maybe at least you understand what you're up against so If you haven't got that far then then you really are behind at this point in the assignment I know that's hard to believe You know in the assignments that we've given you you be before there's no way to be behind until like two hours before They're due right, but you're actually behind You know like under three weeks left to go This week as I suggested I would I would focus on finishing the file system system calls again To the point where you can pass the file only test and some of the other tests to pass to that point Which would leave you a couple more weeks for doing the process related system calls We're actually quite a bit more difficult. There's more code to write In the file system ones as you guys are understanding you're sort of connecting two interfaces You're essentially writing You know a code that's sort of connecting the system call interface with the lower level VFS interface and a lot of the code that's there is already written for you When you get to the process related stuff, that's not true, you know, you're writing those from scratch Okay Any questions on assignment? to logistics blah, blah, blah, but I mean this is all Going to work. This is how we're gonna do things from here on out There's really no changes to how you submit how we grade things blah, blah, blah Next target is assignment two or two point two. I think you can use both and And Off we go. All right, cool All right, so let me I just want to just a quick public service announcement today About how sort of people treat each other when you work in groups When you're in a class together when you're on the forum, so let me put it this way There's like an exchange rate between being an asshole and being good at something and that exchange rate is really high Like you have to be really really really really really good at something to get away with just being a tiny tiny little asshole from time to time Okay, so think about how you're gonna allocate your resources here, right and and you know to some degree I can confess I've performed this experiment, right? It didn't didn't work So the the point is that what matters at the end of the day what matters in the day is You know, did they come away with a good impression of you? Maybe the impression they came away from of you is that you can't do that particular thing That's fine. That's an okay impression. That's a positive Since a jerk, right? So just don't do that. It's not that hard It is it is hard a little bit because again, remember you're overestimating how nice you are about things, right? You need to round up a little bit there. All right, so just you know, please keep this in mind that you guys work together Work with your partner communicate on the forum and things like this This trust me like you talk to people in tech They don't care how talented you are They will not hire you if you have a some sort of problem get in along with people and in the way you treat other people They just don't want that. Nobody wants that. It's not fun. Okay Questions from last week's material any lingering doubts. I don't know what was covered because I wasn't here Interrupts, threading, context switches, so it all makes sense Carl, Carl preached the truth He brought wisdom. Okay, good So I think where we left off is talking about threads and thread states So the thread is this abstraction that we use to represent the state of the CPU when I context switch a thread off the CPU I need to save some information so that I can restore it later When we think about threads and this becomes important when we talk about thread scheduling The threads in the system are in one of several states at any given point What's what are some of the states that they can be in? What's an obvious state? Running so what does that mean? It means a thread is actually executing on a core Remember a thread thread can only be on one core at one time a process can have multiple threads So a process can actually be running on multiple cores at one time, but the thread is only running on one core at one time So a thread could be running Executing instructions, you know do doing business. What else? Sleeping so so what is sleeping or waiting imply? There's implication here If I'm waiting or sleeping What has to happen? Well remember if I'm not running that I'm assuming I performed a contact switch where I can get myself off the CPU, but but what? What has to like? So so from a scheduling perspective, can I pick a thread that's sleeping and put it on a CPU and run it? Yes, no Yes. No, I Hear both. I like this confusion Carl's not perfect. I thought maybe I just let Carl do the rest of the class But clearly clearly Carl has left some seeds of doubt. It's probably my fault in the slide. It's not his fault Waiting so can I take a thread that's waiting and just run it? Yeah Right, so threads that are blocked or waiting are stuck they cannot run they cannot run until something else happens What are some examples of that thing happening? Lock right so imagine I'm using a lock to defend a critical section I cannot let a thread continue until it acquires the lock if I do then the critical section is broken So the thread that is sleeping on that lock cannot run again until that condition changes. Yeah No, usually usually I could but that would invalidate something that I want to happen, right? So for example, give me another example of what I could be waiting for so if I'm waiting for a lock And I just jump in there and start executing I'm inside a critical section probably with another thread Right, and that's the exact reason I created locks in the first place was to avoid that. What else could I be waiting for? What's that? Okay, yeah, so give me give me an example waiting to print something. That's awesome I've never thought yeah, so so what would happen if I if I was waiting to use a printer and I just jumped in and started printing I Have no idea actually, but it probably wouldn't be good for the printer Right like jarbled stuff would come out or whatever If you ever guys printed raw post script before every department has somebody who does that periodically And there's like thousands of pages with like two characters on each line, you know, anyway No, yeah, so so but more common for an OS level I might be waiting on like a disk read or write to finish so I said, you know remember sys write I've got a buffer. I want that printed if I'm reading. I've got a buffer. I want that filled I don't want to continue to execute until that's true because if I start running the buffer doesn't have the data in it That I wanted just got garbage so threads that are Blocked cannot run right something else has to happen in order to free them The other the other state that's interesting here is ready So a thread that's ready can run but it's not running and So why do I end up with threads that are in the ready state? What has to happen? Before I get threads that are in the ready state. I mean threads can block for all sorts of reasons I owe blocks, you know timers all sorts of reasons Why do I end up with threads in the ready state? What's that? That's how I get them there But what has to be true in order for a thread to be in there to be threads in the ready state? There's a there's a property of the system that has to hold. Yeah, you're close, right? Just because all cores are busy doesn't mean anything's in the ready state. I need one more thing to be true I need another thread that's ready to run, right? So when the number of threads that can run is greater than the number of cores that are available I'm gonna end up with threads in the ready state and so to some degree the the process of thread scheduling boils down to How do I move threads between the ready and run state? So that the whole system makes as much progress as possible All right, and and you know and and we can think about some of the the transitions here, right? So a thread goes from running to ready So what happened here? Gave it away remember it goes from running to ready so it's running and at some point it gets stopped But it's still ready to run so what had to happen here So I'm gonna cut like hi It was this was what we call Descheduling the the kernel said you've run for long enough performed a contact switch That's the exact mechanism that I used to get it off of the CPU and put it in the ready state, right? What about this running to weighty now note that these are two completely different transitions Right a threat can go a threat can be running and suddenly the OS says you've had enough time I'm pulling you off or it can go into the weighting state. What triggers this? Some sort of action that the thread itself took I tried to do IO. I tried to grab a lock whatever, you know So this is you know a thread performed some sort of blocking operation It could have been a system call it could have been some sort of synchronization primitive I was trying to use inside the kernel whatever right and so the difference between these two is that in the top case The kernel is doing this to the threat the kernel says you're done. I'm going to schedule something else There's a few cases where a thread can ask to be Rescheduled through something like yield, but that's rare We use that you probably you guys have seen that in our test cases We use that in our test cases to try to get a good mixture of threads at the beginning But that's not a normal thing to do right normally a thread wouldn't voluntarily say oh, I don't need the CPU Somebody else should go ahead, right? But it's aren't like that. Remember they're male. They don't do that All right, so running a waiting a thread before the blocking system calls So that's something that the thread itself would do right that would cause it to not be able to continue It gets put on a queue somewhere and it and it off it goes waiting to ready So a thread was Waiting for something and now it goes into the ready state. What does this imply? Whatever it was waiting for happened. I was waiting for IO to complete. It's done. I was waiting to get a lock I have it whatever And then finally ready to running This is the scheduling operation So a thread was scheduled again. Remember what I said before Scheduling is adjusting what threads are in the running state and what threads are in the ready state and the way the operating System does that is it moves them back and forth as needed. What's the mechanism just a little bit of review from last week? How do I perform these transitions? How does the operating system get a chance? To move a thread from the running to the ready state. I Mean I'm a thread. I'm running on the CPU. I'm happy off. I go I'm not going to yield. I don't want to give up the CPU ever. I've got important to just apply the compute How does the kernel get control? How does the kernel get to run? How do I get to yank that thread off? Timer it drops, right? So did these top two things correspond with preemptive scheduling? It means that from time to time as needed the kernel is going to preempt the thread that's running move it out The CPU and run something else. All right Running determinate it. I can I can exit or hit a fail exception So that's how the threads leave the system, right? And then if I was wanted to be really accurate you put fork on here or something like that a way to create new threads all right Okay, so scheduling is the process of choosing what threads to run So moving threads back and forth between the ready and and the running queue And you know one thing that you might think is interesting is is I have machines with more and more cores The this this question is is more interesting There are some interesting features to multi-core scheduling that we're not going to talk about but on some level multi-course make Scheduling a little bit easier right because on a single core machine if anything is working I always have a problem because if once I have two threads, I have a scheduling problem How many threads do I need to have a scheduling problem on it? How many threads do I need to have a skeleton problem on an eight core machine? But it's even more than that's nine that are actually ready to run Keep in mind a lot of threads spend a lot of their time blocked waiting for network packets to arrive or for you to type a key Or something like that I mean bash spends most of its time waiting for your slow fat fingers to type in keys Right, that's what it spends most of its time doing just sitting there waiting for you If you ever look at the CPU time of bash the the amount of time It's actually been running is tiny tiny tiny fraction of the amount of time you've been using it because most of time It's sitting there waiting for your slow fingers, right? Especially if those of you that can't type very well so Yeah, so scheduling, you know And so I need to have a scheduling problem on multi-core machines I may not always have all right and and we're going to talk primarily about multi single-core scheduling There's some interesting features of multi-core scheduling. Maybe we'll get back to that at some point Particularly when you start to think about caches and locality and stuff like that But but you can think of the problem is simply you can reduce the scheduling problem to single-core scheduling And it preserves most of the interesting features. Sorry that we want to talk about All right, so why does the kernel? Have to perform scheduling like why is this our problem? Yeah, I mean, you know the Wind once we have more threads than we have CPUs. This is CPU multiplexing. Remember, this is the kernel's job You guys talked last week about how no kernel the kernel gets this privileged role on the system It runs first, you know, and it becomes the gatekeeper for how everything else gets access to the system And so this is our responsibility along with that privilege of you know making these decisions comes the responsibility of trying to make them Well, and you know bad scheduling can really reduce application performance. Yeah Yeah Right Yeah, and and I think the question has to do with Multi-threaded processes and how do I accommodate those? I mean on some level what the kernel is scheduling our threads So if a process creates a bunch of threads those threads are being scheduled independently now, that's not entirely true I mean, I have to think about fairness issues between multiple processes and I also have to think about There's some consideration played in certain schedulers to the fact that two threads are from the same process, right? They might run better on a core that has better cash locality or other things like that, right? You could you could do that Yeah, but but on some level remember one of the reasons of having multi-threaded processes is I want to take advantage of this concurrency Right. I mean the reason that a lot of new languages give you a lot of concurrency is because I want one process to use all of the cores Right. I mean, that's one of the cool things you can do with languages like go is I can very easily create Single programs that make really good use of 8 cores 16 cores 32 cores, right? If all I'm doing is running one task from any process or one thread from any process that I lose that, right? And again on a high-core count machine if there's nothing else to do I might as well let your process have all the cores, right? Yeah, it's a good question, but yeah, certainly multi-threaded Processes complicate this a little bit further, right? All right When is so so going back to our thread say transitions? When do I have the chance to make scheduling decisions? There's a couple of points, right? And this is sort of good review So when does the kernel get a chance to make a scheduling decision? What's that? Well, that's when I have to make them but when in time do I actually have the chance to Shuffle things around when can I move threads between the ready and the running? What are some of the events that take place? Yeah, please Yeah, what's an example something that would generate an interrupt that would give me the chance to do this So the timer interrupt that I set up to enable preemptive schedule and absolutely like that gives me that's remember What I do to make sure that I have a chance periodically to reschedule threads But what else do threads do that give me a chance to do this? They do they do blocking system calls and other things so anytime a threat makes a system call It doesn't have to come out You know it can make the call and that call might be like get paid It might be something that doesn't have to block at all, but the kernels like aha This is my opportunity right you're running in the kernel now and if I want to I Can move you on to the ready queue and run something else, right? But certainly anytime you do anything that sleeps when a thread does a blocking system call I have to run something else I've got nothing else to do that thread ends up on a queue waiting for Io to come back and the kernel has to Choose something else to run so that makes me make a scheduling decision If I have a timer that goes off that's a way to grab control from threads that aren't making system calls It may not give me that opportunity What happens when there's nothing to do? It's something I've never covered before in the slides, but maybe it's not obvious Anyone know What's that? Well, yeah, hopefully right there's like ghosts in the machine that get a chance to run It's like ooh now that's steady at home. It's built into your machine. It runs in the background all the time Yeah, there's usually something called the idle idle thread or the idle task I think on sys 161 that just consists of a bunch of no ops on on modern machines if that goes on for long enough The kernel may decide to turn cores off It may say I don't have enough work to do so I'm going to power that core down Saves some energy Particularly on battery powered devices, but it's usually some sort of meaningless little calculation you can find in every kernel that just kind of like sits there either doing nothing or Sometimes that you fire a timer periodically so you can wake up again and see if there's anything else to do But you basically just sort of go into some sleep. Hopefully nothing else all right Okay, I'll set that so And what I just said, you know, I mean in certain cases there are places where particularly in user space thread libraries It's useful to call yield but The modern kernels don't depend on threads calling yielding voluntarily giving up the CPU So there are on most systems ways to say you can you know, I'm not I didn't do a system call But hey, here's my chance. Here's your chance to de-schedule me if you need to All right, and then you know and some of this you guys already talked about so we talked about the mechanisms of how we do scheduling We do a context which and we just moved the thread around internally So we need to keep keep track of what's going on, but this is all based on stuff that you guys talked about last week Now how we do this is what we're going to talk about today and on Wednesday, right? How do we choose which which that's right? All right, this is the first example of something that we're going to see Repeatedly like I said before I mean we usually build up We start with the mechanisms in this class and then we get to the point at which we're talking about policy But one of the things that's really important to notice is It's usually a goal when building complex systems to try to separate the policy and the mechanism as much as possible a Well-designed system gives me mechanisms that allow me to build lots of interesting policies What happens when these two get intermingled is there's something about the mechanism that? Biases the system or maybe in you know There's there's something that causes it to behave a certain way That's built into what I'm trying to do and I can't make as intelligent decisions on top Does this make sense have people talked about this before? Paul has anyone ever heard this before? Heard these two words in the same sentence all right, so this is also connected a little bit with Good interface design, which we talked about in the past I Good interface tries to make sure that the mechanisms can change while the policies are described by the interface and not not changing You know deciding what okay, this is a stupid slide right so these were examples of policies and mechanisms There's a making decisions about which thread to run. That's a policy The ability to move threads around is a mechanism, right? What about maintaining cues that have different threads in them? Is this an example of a policy or a mechanism? Who thinks it's a mechanism? Yeah, this there's no scheduling policy Described here. This is just bookkeeping. It's just making sure that I don't lose track of threads I don't accidentally like forget that a thread existed and like it vanishes into the ether or never runs again, right? Because that would be bad About what about if I try to give preference to interactive tasks? It's a policy and you can think about I mean giving preference to them involves Performing context, which is at the right time and moving threads between those cues in a certain way About using timer interrupts to stop tasks as they're running It's a mechanism this allows and on some level This is an interesting mechanism because it gives me ability to to implement certain types of policies If there was no way for me to stop like a runaway Thread that started to compute pi or something like that Then the policies that I would implement in the scheduling would be different What about choosing a thread to run at random Policy or mechanism? Yeah, this is a scheduling policy. It may not be a very smart one, right? But it's still a policy about how I choose threads to run Alright So let me try to emphasize how important CPU scheduling is You guys may have never thought about this before but in order to do pretty much anything on your machine Something has to run It doesn't matter if it wants to send network packets Use the disk draw to the screen You know detect keystrokes whatever it is the application has to run on the CPU Does that make sense? I mean there's there's no like Mystical magical ways for a sleeping thread to be like let's draw some pixels to the display That's not what happens sometimes you can put things in a buffer and that happens later But there's there's this process by which the CPU starts to gate every other resource on the system So in order to do anything I have to get to the CPU first now frequently All I'm doing is I'm getting to the CPU in order to tell some other component to do something And then I'm going to end up on a waiting queue or whatever, but I still have to run Right. There's no way to kind of like there's no way to get around this So the CPU ends up being sort of the top level gate to every other resource on the system Now like I said, it's it's common that what threads want to do is just use the CPU So that they can get to some other thing and they go to sleep And that observation guides some of the scheduling policies We're going to talk about right this idea that a lot of threads don't want to do lots of computation They just want to use the CPUs so that they can you know write to the disk or you know Take some data from the network and move it somewhere else, right? I've just but I still need to run Now And I wish we could do this experiment. I wish there was like a I don't know Maybe if I ever work for Microsoft again I'll convince them to put some like crappy scheduler mode on their computers, right? So you can see what really bad scheduling is like right because that would be fun Right like turn you see how slow your computer can feel right? I mean there's times when your computer already feels pretty slow and it's trying to be smart so a match of it was really dumb and You know and so intelligence scheduling effectively makes use of you know System resources and it will make even a moderately powered system feel very fast and responsive Whereas bad scheduling can make even a really powerful system feel laggy And I have proof of this because I have like a 20 core Xeon system under my desk and a bunch who is Terrible on it. It's like you know you hit keys and it's like oh there goes the screen, right? So there's no reason for that because I know that this is like a super powerful machine It's just bad software somewhere right so trust me if you want to come use my system sometime and get a sense of like What several thousand dollars worth of CPU will buy you in terms of poor interactive performance go for it, right? But again, this is my this is my proof because that machine should fly and it doesn't always It like sometimes like even the browser windows slow down. I'm like what is going on down there? Like what are you doing? Maybe there has a virus who knows? All right I'm gonna focus our discussion today on interactive expectations for computers We'll talk a little bit about servers along the way, but that's one big Sort of gap here when we start talking about how we allocate resources between different types of machines I think it's more interesting to talk about interactive performance because you guys experience it in a visceral way Now with the cloud and things like this. I mean, maybe you guys see some of this from time to time But but let's talk about sort of your expectations on On machine so what do you guys? What do you guys expect from from your machine? Another way to address this question is How do you notice that something is going wrong? All right, sometimes we don't understand our expectations until they're violated So what's something that your computer will do that you find really annoying that makes it very hard to use? Yeah, damn All right, so like unexpected high CPU usage, right? But what is that typically accompanied by? Because on some level okay, it's a little annoying if the fan is on right, but what else is happening? Does that bother you inherently if your fan is running? Okay Got some curmudgeon's over here. Just let the fan run sometimes the fantasy wants to run You know like I've been I just need to get going it kind of loosen up a little bit Yeah, yeah, so like okay startup delays, right? You double click on an application. It takes a long time to load Okay, what else what about as you're using an application, right? Yeah Yeah, like this does well, that's usually buggy code, right? That's usually not the result of bad scheduling But what's like what's something that happens on these devices? You guys know the mouse will stop working or it's like a little laggy, you know like you move it It's like oh there you know, and so it's like it becomes very hard. Does anyone sorry I'm gonna just yeah Yeah, yeah, let's get there But yeah, so so anything where it's like it's hard to and you guys have gotten the point where it's like hard to enter text Because it's like a little bit laggy like you click somewhere and you think it's working But then it doesn't or you click again, and then you get two clicks, you know So so my little story, but does anyone shop at Wegmans here other than me? Okay, does anyone use those things in the produce area where you can put the those things are terrible, right? Maybe it's just my store, but like you hit the key and it's like Wait, where am I I'm still in a grocery store. All right, okay Like I'm supposed to let you you're sitting like what is going on like and then of course You know I've hit the key four times by that so it's like four four four four, and that's like asparagus or something like that It's like no, it's not what I have right those things are miserable I don't know who made that but that's like if that's what you build when you go out in the world Like don't do that right don't be that person like somebody's responsible for that code Okay, and it will be fun if we could get a hold of that code to make fun of it Of course we can't we just make fun of what became but think about it like Anyway, whatever I'll stop here, but my smartphone is more interactive that thing I guarantee Wegmans paid like a thousand dollars per unit for those things. Yeah, I haven't used those I don't use the self-check on right now. They only there those are new it Yeah, those are new at my store and you have to have under 15 items. I never do that, but yeah But I hate those products But yeah, so we expect responsiveness right when I click on something I want either one of two things to happen I wanted to do something do the thing I wanted or at least I want some visual indication that something is happening And you might start to notice this when you interact with your machine all the different little visual cues that it gives you that Something is happening right the button background changes color a little bit like even if it takes a second for something else to Happen that's still indication to you that okay. I heard you I got it you clicked on that thing I'm working on it. You see waiting indicators other things right So here's here's another expectation right so so YouTube movies I mean how many people have ever experienced interruptions in their YouTube movie, right? I'm watching something and then suddenly in the middle it stops like that is I don't know why it's kind of irrational But that's like one of the most irritating things that the computers can do right is like that would like right in the middle Of like a really funny joke, and it's like or buffering, you know So that's not good There are certain cases, and this is for certain types of behavior where we expect computers people to continue to do something Sort of reliably over a long period of time, okay And then the last thing is this idea of being able to complete certain tasks So like compiling your code, right now that may be at the If most of your machines are fast enough that a lot of compiles become like a almost like a responsiveness thing Like is it done yet? It's been two milliseconds, right? But on older machines It was like I fired up my compilation of the Linux kernel and then I went away and I got coffee and you know I did some shopping and I came back and it was still going right But I actually do want that thing to finish right and and whether Whether it takes ten minutes or ten hours is kind of important to me, right? Does anyone do anything with their computer that falls into that category? Does anyone ever got in the point where like you're really praying for like a 2x speed up Like a 2x speed up would really help me right because it would mean like a week to three days You guys got to find some cool stuff to do with your computers, right? Yeah Yeah, yeah, so Ed builds Android platform The Android platform for our phone lab phones and that can take like what an hour Hour and a half yeah, so imagine if I could get 10x out of that it goes from being 90 minutes to nine minutes Right like that introduces a new development cycle into my life, right? Okay, so responsiveness So this is probably I would argue one of the core components of good interactive a good interactive experience, right? You don't even have to finish the thing that I asked you to do I just need to know that that we're on the same page, right? If I'm typing if I'm trying to click on stuff if I'm scrolling down a page, right? I mean the ability of the machine to respond to these type of events is really critical, right a Lot of what we do with our computers consists of these type of interactions To some degree right once you guys find the YouTube video that you want to watch then it's more like a TV But getting there and doing other things online. I mean that's kind of what distinguishes computers and television, right? And again, it might not finish right away But the idea that my input has been accepted and the computer is working on it and I understand that is really critical So examples of responsive tasks, I mean you guys already mentioned a couple of these Clicking on stuff right when you click on a link in a web in a website, right? You know it may take a minute to load that new web page But there's a series of signals that the web browser is sending me that this is what's happening, right? So I can avoid clicking on the same place a couple of times Same thing with editing, you know moving around in an editor typing these types of things You might think this is kind of basic But if you think about all the work that your editor has to do to do syntax highlighting and layout and all sorts of things This can actually be be a little bit of an issue not for me I use Vim right which does end of those things, but if you use like these fancy new editors Actually, I started started trying to use Adam recent lives like this is a little laggy like that's not good I don't like that Anyways, but yeah, if you use like a very very dumb editor doesn't do anything But modern editors do and so there's a fair amount of work that they're trying to do behind the scenes Same thing with chatting text messages hang out stuff like that, right in any delay that you introduce into this process Is is problematic, right? so So what's the what's the sort of scheduling goal that comes out of this when you guys Input data when you guys click touch tap whatever it is the computer should should jump to right something should happen and There's a there's a very very sort of short timer that goes off in your brain when you click on something Where you're starting to expect something else to happen and when that timer goes off or goes off ten times in a row When I'm at Wegmans, right like you start to get very frustrated all right Continuity so when you ask a computer to do something and continue doing that Thing over a long period of time now. This is an erase Okay, that's the difference between this and the next task You don't want to watch the YouTube video as fast as possible, right? You're not asking your computer like download it and show it to me as fast as you can, right? You're saying for the next half an hour I want you to at intervals Continue to fill the frame buffer and deliver, you know smooth video or smooth audio if you're using things like spotify And and there's there's there's some active waiting involved here, right? There it's not the same thing as click where it depends on your input But you guys notice when this breaks down, right when the spotify fee goes out or it starts to get a little Jumpy or when the YouTube videos starts buffering or whatever or when there's a little bit of jitter in it I mean we're pretty sensitive to this So so we'll notice this Blinking cursors does anyone still use a blinking cursor? No one Of course you do everyone does Okay, good There's this whole you can if you Google blinking cursing you could find this whole web page about how blinking cursors are like the equivalent of Chinese water torture So maybe they finally got rid of them in most places I think a bunch of for a while still came with blinking cursors and you had to like Issue these magic spells to get it to stop But yeah, but blinking cursors. I mean have you guys ever looked at your machine and see the cursor Blinking get a little wanky, you know, it's like Yeah, yeah, you know see if you use it just goes up Anyway, I mean, maybe that's just me maybe there was something else going on when I was looking at the curse Anyway, so like playing music playing movies, you know again You know little stupid web animations, right ads that run on the side of websites I mean these are things that we expect there to be the smoothness of purpose now again These are not necessarily loading the machine down in every minute But there's this expectation that I can schedule little bits of work Periodically over a long period of time and and make sure that certain invariants are met All right, the last thing here is this idea of completion so the idea that I'm going to be able to give the computer some work to do and The work's going to get done eventually Now you may not be even aware of this happening You know a lot of the things that the computers that we use are doing passively are not necessarily things that were even Cognizant of you you may notice when they stop happening if they don't happen for a while, right? Now like I said, I mean these these may not be things that you're starting But these are the things that computer is doing periodically Anyone give me some examples of these like a long running background task something that should finish That the operation of the computer is predicated on it finishing, but you may not really realize this happen Yeah, okay, that's fair window software updates, right? I mean like those usually notice because there's 82 pop-ups that that are generated and warnings and stuff like that But yeah, I mean if your computer stops getting Windows updates for a while There's gonna be like angry red messages flashing everywhere right and eventually Chinese hackers or Russian hackers or Hackers from somewhere are gonna have control of your machine So okay Windows updates. What else? Legal torrenting I like that. I mean I mean illegal torrenting also falls in that category. I'm just gonna point that out, but I like I like that like a legal torrenting Torrenting of which I only perform the legal variety. That's that thing, right? Yeah. No, that's a great point, right? And and here's the thing about torrenting. I mean torrents to some degree the existence of The the torrent ecosystem relies on people not noticing that they finish right because you're supposed to not notice and then you're gonna seed for like 30 years until the FBI shows up, right? Like that's how torrenting works System backups does anyone backup their system? Okay, well anyway Okay, let's put it this way restoring your system without a backup good that that you'll notice, right? Indexing files this one of the things you guys don't even there's anybody use spotlight or the windows Does windows still have like a dog that comes up to help with things or is that? See you guys are so young. You don't even remember that come on. There's like a whoop whoop. Hope you find things It's like I mean it's like a The thing I never figured out is dogs are not good at looking for things Dogs are good at like fetching things. I have a dog So I know I first-hand knowledge like knowing on bones, but why they thought a dog was like good Oh, go look for your files. It's like no, it's not it's gonna go like eat some cat poop and get sick That's what a dog is gonna do. It's not gonna help you find files But anyway, I mean does windows still has that right like a fine files thing like the way these things work is they build indexes constantly, right? Spotlight or whatever the Mac thing is I mean it doesn't actually go look at your files every time you type a search query that'd be way too slow That'd be like Google being like oh you entered something into my search engine Oh, okay Well now let me run my web search indexing and find all the no it's not how it works. I mean it's all done before him So yeah in file indexing Antivirus software falls in this category. That's running. It's doing things, you know, you might notice if it stops But you don't notice it's happening. Okay So a lot of applications, you know on some level build Multiple of these expectations in some music player is a great example or I no one uses music players anymore This is all just web browsers web browsers web browsers, right? So but imagine a music player page loaded into your web browser I hit click Well, what's a click type expectation for a music player? What's the place where I like I wanted to do something based on my input? Yeah play stop You know imagine if it hit stop and it was like I'll cue that later, right? You know like yeah, you got some song player I'm like I'm in here playing a song and the mad guy from geology comes in It's like I'll get to that later like what's I'm done with my file indexing. Oh, yeah, so responsive, you know Change tracks. What about like a continuous sort of thing? That's obvious, right? I mean playing that playing the track itself That involves a series of actions that have to be continued a period of time Updating album artwork building indexes of my music collection stuff like that Oh, these are all sort of like long-running tasks that get done in the back web browsers are obvious, you know This sort of thing all right Now the the thing that makes scheduling fun Okay, the fundamental core tension between scheduling particularly on interactive systems is balancing two goals The one is the ability to respond to new things and the second is the ability to get things done and Make best use of system resources in order to accomplish a lot of things at once So if you if you do optimal resource allocation It's very difficult to meet deadlines because meeting deadlines Requires that the system constantly be ready to drop everything and do whatever sort of weird new thing That you told it to do so imagine your system is constantly like, okay I'm gonna plan for the next 10 minutes like here. So I'm gonna lay out the CPU here So I'm gonna lay out disc here's what I'm doing with an artwork. This is awesome. I know exactly what's going on Oh, no, we switch applications, right? Like and you're doing this all the time, right? I mean you're constantly like you are the biggest scheduling problem that the computer faces because you keep doing things that it didn't expect It's like, oh man, why is he going to that website? Right? I was just on that other website So, I mean, you know, your your unpredictability is something that the system is constantly trying to try to keep up with You know and responsiveness it has these unpredictable deadlines whereas continuity has these predictable deadlines, but again your your Unrisk, you know your unpredictability be can be constantly changing the mix of system resources and causing the system to focus on new things, right? I mean Switching pages in a web browser is a mild version of this right the extreme version is like you've been using chrome It's only we'll launch Photoshop. It's like, oh my gosh. What just happened. I mean, there's a totally different thing, right? So the the tension between these is what makes this interesting, right? It's what motivates some of the schedule in the algorithm to talk now, you know on interactive facing systems The preference now again, this is where we this is where the goals of servers and user-facing systems diverge slightly This idea that on an on a user-facing system deadlines typically win, right? You guys are sensitive to these things like Interactivity you're sensitive to things like rebuffering events and jitter on on continuous audio or video or things like that You're not as sensitive to knowing exactly when the file index that the system ran in the background finished It's like no one cares, right do it at night, you know, whatever I mean, it's done periodically some of the stuff you guys aren't even aware of is going on the first place, right? You know, you know no one and the other thing that you guys don't care about is How well the system is using the resources it has, right? Like you don't care if the system is using all its RAM that means nothing to you, right? Does anyone has anyone ever noticed that like you guys measure this does anyone care? Okay, I've got two hands up, right? Yeah No, the system should use all its RAM But I don't want it to use its ramp at the price of not paying attention to me, right? Like you're supposed to use the RAM in service of this goal to be honest If my system can do all this with one stick of RAM, I don't care like don't tell me because I bought the other seven, right? But yeah, I mean to the degree that the system could do meet its deadlines and do the things I'm asking in a responsive way Whether or not it's using its resources is totally irrelevant and you guys don't care. You don't track this You know and here's the fundamental difference, right? And here's what makes this fun, which is that your time You know my my just like with my dad the other day and he's convinced that like robots are going to take over all of your jobs Okay, he's like I'm really glad I'm retired because he's reading some scary book about robots and You know and okay, fair enough. I mean computers are really powerful That's a good thing to think about when you make life choices Like if you can do a job that can be easily replaced by a computer. I would probably find a new career, okay? But right now your time is still way more valuable than your computers You know so when your computer is wasting your time, that's when you get frustrated, right? When you're trying to do something that you think should take just a few seconds Like I just want to send this text message and it's like hangouts is loading loading. What is going on? I just didn't do what I want The wasting of computer time let's put it this way There is a lot of computer time out there to waste, right? If you want to waste some computer time this computers have time to waste, right? All these phones that you guys are using they sit there at night plugged in for eight hours doing nothing, right? I mean if you can figure out how to get them to cure cancer in that time Please do that right because they've got they've got scores to kill like Google is like desperately trying to give away CPU cycles Because they've got so many machines in their data centers to handle diurnal fluctuations at night They're not doing anything right again if you have an algorithm to solve cancer and you need 10,000 machines We will find those machines for you. It is not hard, okay? There's a lot of a lot of power out there in the world and it doesn't matter if a little bit's wasted a lot of its wasted Right software is terrible. Okay software waste a lot of cycles, but it doesn't matter because there's a lot of cycles to waste Okay So before we almost done I think we're almost done before we finish up today. Let me let's go through some Scheduling goals, right? So this comes back to our expectations How what does it meet deadlines both predictable deadlines the deadlines that you know? I can imagine in the future because I know periodically I have to wake up to fill the audio buffer and unpredictable deadlines you deadlines that are created by your stupid fingers touching things right or moving mouses around or Talking to your computers. I guess people do that now not me, but How completely does the system allocate resources again? I don't want it when I have really Beefy stuff to do. I want to make use of all the resources in the machine and On human-facing systems deadlines way on servers not always right, but you know bring this into the cloud errors, right? So why why are cloud servers now potentially a lot more interested in deadlines than they used to be? There's actually a fair amount of deadline attention now being paid in big data centers, why? Yeah, I mean there's a lot of applications and websites that are built based on cloud backends, right? So that cloud API call that's in your interactive loop, right? When you guys use discourse like the way discourse works is it loads of web application in your browser And then it's making API calls to the back end so that thing may think it's a server But when you click like click new post again that latency is now inside of your brain, right? It's not hidden back away in some dark room, right? You're waiting for a cloud server, right? And understanding how that latency fits in to the other forms of latency on the device is actually something that people are Still working really hard on all right, so We're not going to talk about real-time scheduling any questions about this So on Wednesday, we will talk about some simple schedulers. We'll talk about some ways to evaluate their performance And then we'll talk about some slightly more sophisticated schedules and on Friday. We will talk about obscene scheduling