WEBVTT 1 00:00:02.399 --> 00:00:15.360 William Cheng: Welcome to the Week three discussion section. So, towards the end of week today's discussion section I started to talk about warm up to so 2 00:00:15.960 --> 00:00:23.700 William Cheng: I guess today, I decided to make some changes to it. So, last Friday I went over this slide. 3 00:00:24.450 --> 00:00:30.480 William Cheng: So you can see that this slides a little different from last time i also as I sort of deleted stuff on the last lecture slides. 4 00:00:31.350 --> 00:00:37.170 William Cheng: So let me just go briefly through it. So today I'm going to talk about the top part over here. 5 00:00:37.710 --> 00:00:47.970 William Cheng: So this is considered sort of the first part of warm up to you just have to do the simulation, you don't have to worry about control CCE. Okay. So, in the first part of warm up to and this is going to take up most of your time. 6 00:00:48.480 --> 00:00:55.800 William Cheng: You need to learn how to use the piece I mute tags and Peter condition variables correctly. So there are four functions that you need to use 7 00:00:56.250 --> 00:01:02.940 William Cheng: What is peace, a new tax law and then Peter meter a lot right and the other ones. Peter condition way and Peter condition broadcast 8 00:01:03.360 --> 00:01:08.520 William Cheng: If you read the spec for the warm up to it will say that you must not use piece recognition signal. 9 00:01:09.210 --> 00:01:13.260 William Cheng: Okay, so which means that if you want to wake up a bunch of threads that are sleeping in the condition variable. Q. 10 00:01:13.830 --> 00:01:21.570 William Cheng: You know, if a warm up to you have to use Peter condition broadcasts. Okay, that's a requirement you please do not use P three conditions signal. Yeah. 11 00:01:21.990 --> 00:01:32.550 William Cheng: And the rest of our sort of covered in the next discussion section, you know, the next week. So this is about handling control seat. So if you read the spec, it will say that, you know, when Control C is press 12 00:01:33.030 --> 00:01:38.310 William Cheng: You need to have graceful shutdown. We're going to leave that until next time. Okay, so, so in that case. 13 00:01:38.790 --> 00:01:53.130 William Cheng: Some of the function, you need to call is sick programmatic way Peter cancel. You also need to be able to manipulate cancellation. So again, that's all the for next week. So today, we're going to sort of focus on the on the first part and talk about the simulation. Alright. 14 00:01:54.720 --> 00:01:59.430 William Cheng: We are simulating this token bucket filter. Right. So today, we're going to sort of go over some of the details over here. 15 00:01:59.670 --> 00:02:05.520 William Cheng: Your job is to implement for threats. Right. And these four threads. So the idea here is that the four threads are working together. 16 00:02:06.030 --> 00:02:10.410 William Cheng: Okay, so, so some people always asked me, said, How do you know the other what the, what the other thread is doing. 17 00:02:10.740 --> 00:02:18.300 William Cheng: While you write the code or so you need to be able to control the synchronization among all these for threats. Right. That's the whole point of the exercise. 18 00:02:18.510 --> 00:02:24.900 William Cheng: Is to think about how they interact with each other. So that can accomplish the job of simulating a token bucket filter. 19 00:02:25.320 --> 00:02:31.410 William Cheng: Yeah. Alright, so one thread is over here is called the the the packet arrival another thread is here of what the 20 00:02:31.980 --> 00:02:41.520 William Cheng: The token deposited threat. And then there's s one s to the other server. So the idea here is that you know we we we tried to transmit a packet 21 00:02:42.270 --> 00:02:52.740 William Cheng: The packet, you know, the packet have generated by the packet the packet creation thread the packet arrival threat, however you want to call it. 22 00:02:53.460 --> 00:03:04.110 William Cheng: So what happened is that in order for a packet to be transmitted it needs to have enough tokens. Okay. So, therefore, if it doesn't enough token over here, they need to wait in Q1 and Q2. One is served first come first serve. 23 00:03:04.860 --> 00:03:11.850 William Cheng: Okay, so, so if a packet, you know, get getting the Q1. The first packet of Q1 over here when I HAVEN'T YOU KNOW WHAT I HAVE ENOUGH token. 24 00:03:12.210 --> 00:03:21.750 William Cheng: If he has enough token, it will get moving to Q2. Okay, and then was that went into a packet get move on q1 q2. It needs to remove the right number of tokens for the token bucket. 25 00:03:22.530 --> 00:03:32.550 William Cheng: Yeah, alright. So, if this packet ob gyn doesn't mean that token, he has to sit there and wait and then we have a token a deposit the threat. What it will do is it will keep adding tokens to the it will keep 26 00:03:33.000 --> 00:03:38.940 William Cheng: tokens to the to the token bucket at a particular rate. Okay, so this rate is no as art. 27 00:03:39.570 --> 00:03:45.030 William Cheng: So tokens gonna come in over here. And then when the token get added into the token bucket at this point it should 28 00:03:45.540 --> 00:03:59.160 William Cheng: You know, the token. So it has to check the head of the the QR to see that packet at this point now has enough token. Okay. If it does, what it will do that again it will move it from q1 q2 and then it will reduce number of tokens in talking about it and then we'll continue to do the simulation. 29 00:04:00.180 --> 00:04:06.270 William Cheng: Yeah. Alright. So when either threat. Put a packet into Q to what they should do is that they should wake up all the server threats. 30 00:04:07.020 --> 00:04:14.550 William Cheng: Okay, because the service. Well, you know what they would what. So what would the servers are normally do normally they have nothing to do, right, there's no work for them to do they go to sleep. 31 00:04:15.000 --> 00:04:17.220 William Cheng: Okay, so they all sleep in a condition variable. Q. 32 00:04:17.640 --> 00:04:22.530 William Cheng: So as soon as work arrived, you need to wake up both of them, and both of them will compete for this particular package. 33 00:04:22.770 --> 00:04:31.410 William Cheng: One of them will get the packet. What it will do is it will go to the head of Q2 and he will remove the packet over here and there. What it will do is it will simulate the transmission of that packet 34 00:04:32.340 --> 00:04:41.220 William Cheng: Well guys, how do you simulate a transmission in the packet, while those those warm up to you. You know, you look at the service time for the packet and that's the amount of time you that you sleep. 35 00:04:41.550 --> 00:04:48.570 William Cheng: And when you wake up well then you finish servicing the packet. OK. And then in that case what you check the packet or delete the packet. Same thing. Okay. 36 00:04:49.350 --> 00:04:53.220 William Cheng: Alright, so that's the basic operation. So we're going to have four threads over here. 37 00:04:53.700 --> 00:04:58.830 William Cheng: You can also think about, we have actually have five threads. Right. There's the main thread means there is when I create these for Charles where 38 00:04:59.070 --> 00:05:08.160 William Cheng: The four chapters all work together to simulate the talking about the filter and then the main thread with join with all these four threads when all these four threads are dead, then 39 00:05:08.520 --> 00:05:15.210 William Cheng: Then nobody else is running. So in that case, the main thread the what what that means I could do is that they could print out the statistics. Yeah. 40 00:05:17.010 --> 00:05:22.710 William Cheng: All right, so, so, so if you're familiar with something called an event driven simulate simulation. 41 00:05:23.130 --> 00:05:30.750 William Cheng: Please understand that we are not doing something called event driven simulation. Okay so event driven isolation. They are characterized by the event queue. 42 00:05:31.020 --> 00:05:39.330 William Cheng: And then you need to sort of simulate these event get generated and the event takes zero time to execute. So multiple events can happen exactly the same time. 43 00:05:39.750 --> 00:05:49.170 William Cheng: We're not gonna, we're not going to get too much into it. Okay, so, so just want to, you know, just mentioned all these words over here, what we need to understand is that we need to we need to do a different kinds of simulation. Okay. 44 00:05:50.490 --> 00:06:02.370 William Cheng: Alright, so you can see that here's a sort of a sort of a timing diagram for event Q certain things happen at exactly the same time because you know when you when you process the event. It takes zero time right even though, you know, we try to do the simulation. 45 00:06:02.730 --> 00:06:09.150 William Cheng: We execute code actually go code takes time. But, but as far as the simulation is concerned, you know, these kind of thing doesn't take 46 00:06:10.560 --> 00:06:18.540 William Cheng: These kind of the event processing will take zero time. Okay, so it again. It's very, very different from our warm up to that. So anyways, I'm not going to get too much into it. 47 00:06:19.350 --> 00:06:29.040 William Cheng: We are doing what's called time driven simulation and some people just call it emulation. Right, so, so, so I guess we're going to use the word simulation simulation interchangeably. 48 00:06:29.520 --> 00:06:39.090 William Cheng: Okay, because there's only one kind of civilization that we do is going to be this time driven simulation. Okay. So in this case, there will be no event, you guys. So if you don't know what, even if it's okay. Don't have to worry about it. 49 00:06:39.510 --> 00:06:50.790 William Cheng: Every active object is implemented as a threat. Okay, so, and the active object. So in our case is going to be the packet arrival threat. Okay, so when you, when when the package arrived. It's kind of like 50 00:06:51.930 --> 00:07:02.460 William Cheng: The package arrived. It is generated from some kind of a generator. So a generator is an active object, okay, that the token deposits through so so there's another process. 51 00:07:03.150 --> 00:07:07.290 William Cheng: Should use the word process. And there's another activity that generating token. And so again, you know, 52 00:07:07.800 --> 00:07:12.450 William Cheng: There's going to be in an active object that's generating tokens. So again, that needs to be implemented by by another threat. 53 00:07:13.290 --> 00:07:22.440 William Cheng: The, the server thread there. The one that transmitting packets or so transmitting packet is kind of like activity. So therefore, every server threat needs to be implemented as a separate thread. 54 00:07:22.680 --> 00:07:29.700 William Cheng: Okay, so that's how we end up with those four threads. Yeah. And again, threat interact with one another through the use of shared variables. 55 00:07:30.630 --> 00:07:39.600 William Cheng: Okay, so please understand that there's no way for threats, talk to each other. So if you have 171 CPU and the other thread running the other CPU. How can thread talk to each other. 56 00:07:40.140 --> 00:07:43.500 William Cheng: I mean, there's no way for one CPU to talk to another CPU. You just cannot be done. 57 00:07:43.980 --> 00:07:50.580 William Cheng: Okay, the CPU does his own thing and execute instruction. That's all it does. There's no way for one CPU to talk to another CPU. 58 00:07:50.970 --> 00:07:58.050 William Cheng: Now alright so. So in this case, you know, the way that they interact with each other. They talk to each other is by changing share variables. 59 00:07:58.200 --> 00:08:05.580 William Cheng: So if you change the variable for one to two, you're telling the other thread say hey you know you need to do something. Okay. That's how threads communicate with each other. 60 00:08:06.120 --> 00:08:21.300 William Cheng: Okay, that's the only way. Yeah. All right, and also the other characteristic of a time driven simulation is that it takes time to execute simulation code. Okay. And the time it takes to do all these to execute all this code is part of the simulation. 61 00:08:22.050 --> 00:08:28.860 William Cheng: Okay, so will you try to perform a particular operation operation takes time. That's part of the simulation. Right. So again, this is very, very different one event driven simulation. 62 00:08:29.100 --> 00:08:35.160 William Cheng: You can take a long time to do whatever you're doing. So your simulation is that you've been doing a simulation. But, you know, we 63 00:08:35.550 --> 00:08:46.320 William Cheng: Try to look at the timing diagram, you know, all these events. It doesn't take any time to process. OK. So again, that's that that that's sort of the meaning of this event driven simulation and we're not doing that. Okay. 64 00:08:47.010 --> 00:08:59.100 William Cheng: To simulate the passing of time we have to call you sleep. Okay. So for example, if you want to transmit a packet that takes time. So we're gonna we're gonna we're gonna call you sleep on the amount of time to transmit a packet 65 00:09:00.150 --> 00:09:08.730 William Cheng: Okay, if you want to wait for a packet to be generated. Right. So you say, oh, the package should be generated three seconds from now. Well, in that case, you're gonna call you sleep and you need to sleep for three seconds. 66 00:09:09.690 --> 00:09:15.420 William Cheng: Alright, so, so, so this is what we have to do in a time driven simulation or time driven emulation. Yeah. 67 00:09:16.230 --> 00:09:24.630 William Cheng: Alright, so if doing something will takes x microseconds. So you second OBS is pronounced microsecond because I don't want to confuse with em seconds right and 68 00:09:25.050 --> 00:09:33.960 William Cheng: M stands for milliseconds. Right. So we use whatever you see you second over here is stands with microsecond okay so if you want to, if doing something takes x microsecond 69 00:09:34.170 --> 00:09:39.330 William Cheng: You should call you sleep X read the argument over here. It's a number of microsecond that you want to sleep there. 70 00:09:39.660 --> 00:09:51.120 William Cheng: And please understand that we've been to does not run a real time operating system. The whole bunch of optimism is best effort. So when you tell the operating system to say, hey, I want to sleep with x microsecond, what would the operating system do 71 00:09:51.600 --> 00:09:58.050 William Cheng: Okay. So in a way, kind of its kind of unreasonable for the appliances into sleep less than x microsecond because that seems to be violating the spec. 72 00:09:58.440 --> 00:10:06.390 William Cheng: Okay, so what the system will do is that I will sleep for X microsecond I will wake you up as close to X microsecond as possible. 73 00:10:07.080 --> 00:10:16.470 William Cheng: Okay, so the system is not making any promises the operating system just say I will do my best. Okay, so that's the important thing to understand. You know what a best operating system does. Okay. 74 00:10:18.270 --> 00:10:30.180 William Cheng: All right, so, so you sleep will return more than x microseconds later. Can it be exactly X microsecond, you know, most likely won't be right, but if you have a super fast CPU. Maybe it will be, you know, perfect. 75 00:10:30.360 --> 00:10:39.630 William Cheng: And when you're lucky, you will hit it right on the nose. Okay, but typically is going to take a little longer, and sometimes you will take a lot more than x microseconds later. So a lot of. Yeah. 76 00:10:40.380 --> 00:10:49.650 William Cheng: X microseconds later. Okay, how much more. Okay, so that's the problem. Over here, we don't know because the Linux Linux operating system doesn't make any guarantees. 77 00:10:50.040 --> 00:10:58.440 William Cheng: Okay, so when you ask them to say, I want to see for one microsecond. Is it okay if the micro the if the audience is that wake you up three seconds later. 78 00:10:59.640 --> 00:11:10.140 William Cheng: Okay, the answer is yes, that's perfectly okay because the audience is in think didn't make any promises. So, therefore, if he wakes up three seconds longer than you asked it to, to, to wake you up. That's perfectly fine. 79 00:11:11.850 --> 00:11:19.440 William Cheng: Okay, well then, then how do you know whether you know whether, when you sleep too long, whether it's a bug in your code or whether, whether that's what's supposed to happen. 80 00:11:19.710 --> 00:11:22.020 William Cheng: Well, then it makes it a little bit tricky to debug your code, right. 81 00:11:22.320 --> 00:11:31.350 William Cheng: Yeah, maybe you know when you try to actually sort of sleep on one microsecond as it turns out, you ask the opposite of asleep or three to sleep or three seconds, you just have a bug in your code. 82 00:11:31.920 --> 00:11:43.080 William Cheng: Okay, so that's why the evidence is that wake up three seconds later, right, because of a bug in your code that but it's also possible that you ask them to sleep. Exactly what microseconds, and the operating system wake up three seconds later. 83 00:11:44.460 --> 00:11:48.930 William Cheng: Okay, so it is up to you to make sure that you need to verify that your code has no bugs. 84 00:11:49.710 --> 00:11:59.910 William Cheng: Okay, because the operating system over here doesn't make any promises. So again, you need sort of figure out how do I make sure that my code that bugs. Right. So. So again, that's, that's one of the things you need to figure out. Alright. 85 00:12:01.140 --> 00:12:12.240 William Cheng: So, and also, you may have a bunch of threads or I have one thread 2333 or four threads over here, they all run in parallel. If I have four four CPUs over here, they will run in parallel. If I only one CPU, who's going to run next 86 00:12:13.170 --> 00:12:21.570 William Cheng: OK. So again, don't try to control it, guys. Somebody decided to control it. That's a really bad idea. You need to resist the temptation to control which threat run next 87 00:12:21.810 --> 00:12:32.700 William Cheng: Okay, let your machine. Let your audiences and they do a piece or a library decide which threat to run next. Okay, so, so why is that sometimes you know you know one thing we're on first and sometimes will still run 88 00:12:33.750 --> 00:12:42.960 William Cheng: Some time to run first. So in this case, your simulation become erased the simulation results become erupt you reproducible. 89 00:12:43.740 --> 00:12:54.090 William Cheng: OK, so the results can never be reproduced. Exactly. Okay. Every time you run your simulation is going to be a little bit different, right, because you know when you asked albinism, say, Hey, wake me up at, you know, 90 00:12:54.510 --> 00:13:04.440 William Cheng: You not have, you know, at a 150 microseconds later. Well, maybe, you know, sometimes the audiences and wiki up you know 170 microseconds later. Sometimes you will wake you up two seconds later, somebody 91 00:13:04.980 --> 00:13:16.980 William Cheng: Here one second later, they might be all correct. And so therefore, therefore, if you look at the the numerical result of your program, chances are, every time when you run it, you don't get a different result. 92 00:13:18.210 --> 00:13:22.290 William Cheng: Or is it again. How do you know you know whether your program has implemented correctly. 93 00:13:22.890 --> 00:13:33.690 William Cheng: Okay so so debugging, you know, can be a little more tricky because every time when you're on your program you're going to get slightly different timey going to get a different result. And also if you run the debugger. That's going to interfere with the timing of your program. 94 00:13:34.890 --> 00:13:37.590 William Cheng: OK. So again, you know, we write program like this, you need to keep all this 95 00:13:37.980 --> 00:13:47.670 William Cheng: You know all this in mind and and still be able to try to sort of figure out where your bugs. Okay, so. So the most important thing over here is that you need to understand exactly how the token bucket filter works. 96 00:13:47.970 --> 00:13:55.260 William Cheng: OK, so this way you can actually figure out whether you know whether the simulation has bugs or not. Yeah. All right. 97 00:13:56.040 --> 00:14:08.700 William Cheng: You're going to have, you know, multiple you know threats over here, competing for the same resource. Right. So what is the resource over here. Ah, q1 q2 on over here is going to be a resource that they need to compete. 98 00:14:09.240 --> 00:14:12.780 William Cheng: The, the, the, the pocket thread the token thread. They all need to access Q1. 99 00:14:13.020 --> 00:14:20.460 William Cheng: The package thread the token threat and the servers that they all need to access Q2. Right. So in this case, they're competing for. So, therefore, you have to use them you tax. 100 00:14:20.700 --> 00:14:24.690 William Cheng: So again for this assignment assignment. Please only use one new tax. 101 00:14:25.080 --> 00:14:32.010 William Cheng: Okay. And also another requirement if you read the the grading guidelines and the the spec. It says that you're, you're not allowed to do Busy waiting 102 00:14:32.250 --> 00:14:40.830 William Cheng: Okay so busy waiting, again, is that you're waiting for something so you know you're waiting for some variable to change value and then you just sit there and keep waiting without doing any useful work. 103 00:14:41.490 --> 00:14:44.730 William Cheng: Okay, so in that case, you're gonna burn up the CPU, you're going to burn up your battery. 104 00:14:45.120 --> 00:14:54.750 William Cheng: So against a really, really bad idea. So the requirement is that you, you must not use busy weightings which means that you have to use you. You have to use a CV. 105 00:14:55.620 --> 00:15:05.400 William Cheng: OK, so again lecture, we talked about how, what are the right ways to to use the condition variable. So, in this in this programming assignment you need to practice how to use condition variable. Yeah. 106 00:15:08.100 --> 00:15:20.850 William Cheng: Alright, so, so, so, so in this case, you know, we try to simulate the top of the of the operation of talking about can filter, you know, everything is going to take time. Right, so, so when you execute machine instruction is going to take time. So, therefore, you know, times are 107 00:15:22.020 --> 00:15:27.150 William Cheng: Just going to move forward on like the event driven driven simulation, what time is frozen. Okay. 108 00:15:27.570 --> 00:15:33.810 William Cheng: So here's an example. Let's say the packet one over here. Uh, right into the, into I'm going to call this whole thing of the system. 109 00:15:34.200 --> 00:15:38.820 William Cheng: Okay so packet one at some point is going to get created. Right. So the packet 110 00:15:39.180 --> 00:15:47.940 William Cheng: You know the package three is when the Jerry the packet, then at some point, again, you get to define exactly what it means. Will packet one to arrive into the system. 111 00:15:48.270 --> 00:15:54.060 William Cheng: Okay. So over here I just sort of draw the picture. There's a bunch of, you know, time that can happen. So these are the 112 00:15:54.420 --> 00:15:59.640 William Cheng: Types of what you need to do is that you need to read the system clock, you know, to find out, you know, when did the packet one arrived. 113 00:16:00.060 --> 00:16:09.240 William Cheng: OK. So again, you get to decide when you want to read the system clock. Okay, my recommendation recommendation over here is that, you know, since the system clock is a shared resource. 114 00:16:10.500 --> 00:16:14.970 William Cheng: Okay, because all your threads over here. They're all reading the system class. Oh, you know, so it's kind of weird. 115 00:16:15.300 --> 00:16:23.790 William Cheng: Well, why would the system copy associate resource. But again, in order for your print out to make sense, you need to consider the system class a shared resource right so well. So what does that mean 116 00:16:24.030 --> 00:16:28.320 William Cheng: That means that that means that in order for you to read the clock, you have to have to meet tax locked 117 00:16:29.490 --> 00:16:36.870 William Cheng: Okay, so therefore, at some point, you can unlock the new tasks and you're going to read the clock you decided this is the time to pack the pack. And number one has arrived. 118 00:16:37.320 --> 00:16:44.520 William Cheng: Yeah, so this was no arrival time. So a one over here will be the arrival time the packet. Why do you want will be the departure departure time 119 00:16:44.880 --> 00:16:53.310 William Cheng: Package number. Why so do you want is whenever a server, you know jack this packet or delete this package that will be the departure time again, you get to define exactly when it is okay. 120 00:16:53.940 --> 00:17:08.010 William Cheng: The service time over here is the amount of time that the pack is spent in a server. So that could be one way is to the response time is basically a time in the system there. So the response time is simply the departure time minus the arrival time 121 00:17:10.080 --> 00:17:20.370 William Cheng: Okay, so, so, so again, what you need to do is as you perform the simulation, you need to gather a bunch of timestamps in order for you to compute all, you know, you know, to, to, to compute all these values. Yeah. 122 00:17:21.060 --> 00:17:26.940 William Cheng: Alright, so, so the way you so think about is our package arrived. While we're here at time equals to type equals to A one. 123 00:17:27.690 --> 00:17:31.320 William Cheng: Which is arrival time packet one over here only requires one token. 124 00:17:31.980 --> 00:17:39.720 William Cheng: Okay, so since this is the very first, you know, a packet over here. So what you would do is that you need to lock them your tags and then you need to add the packet to Q1. 125 00:17:40.260 --> 00:17:45.540 William Cheng: Okay, so by the time this packet get onto Q1 time has passed, you know, the time has elapsed. 126 00:17:45.810 --> 00:17:55.320 William Cheng: Guys, okay, you need to take all these seem to consideration. So that's why the picture that drove me here to say that at time equals to A one, the package arrived, but it takes a little bit of time for the package to get into Q1. 127 00:17:56.610 --> 00:18:02.400 William Cheng: Okay. And then what it is that you know there are also these blue curve over here. So this is when the token token. 128 00:18:03.000 --> 00:18:13.980 William Cheng: Token was arriving so token, you know, the blue curve over here says at time you go to zero you have zero token and then sometime later the token goes to one, and then goes to two. And now the package has arrived. 129 00:18:14.910 --> 00:18:25.140 William Cheng: Okay, so therefore we add a packet of Q on over here, this packet has already has enough token, you're talking about it because at this point that token above that it has to token. And this packet only requires one token. 130 00:18:25.860 --> 00:18:28.650 William Cheng: Okay, so therefore this packet needs to be moved into Q2. 131 00:18:29.310 --> 00:18:39.120 William Cheng: Okay. The requirement, you know, simulation to say that, you know, for this token to travel across the system you first you have to add into Q on first and then you need to remove from Q1 and 132 00:18:39.510 --> 00:18:46.230 William Cheng: Q2. Okay. Every time we performed all these actually you need to read, read, read a clock and get a timestamp. I remember what this times are 133 00:18:47.010 --> 00:18:54.930 William Cheng: Now alright so this pocket, you know, needs to be moved to Q2. And then when you get moving to today, you need to document a number of tokens in the top of bug. So they will go to one. 134 00:18:55.290 --> 00:18:59.430 William Cheng: So you can see on this picture over here you know this, the number token hope you'll go from two to one. 135 00:19:00.240 --> 00:19:08.430 William Cheng: Day. So now this pack of sitting and q2 over here and then you know what you need to do is that you need to, you know, so at this time. What a server through one and two are doing 136 00:19:09.210 --> 00:19:17.610 William Cheng: What the service or wanting to over here. So, so they are you know they're there to transmit a packet. So if there's no packet to transmit they're actually they're sleeping in a condition variable cute. 137 00:19:18.390 --> 00:19:24.510 William Cheng: Okay, so therefore, as soon as you add a packet to cue to you have to do you have to call Peter condition broadcast to wake up all of them. 138 00:19:24.990 --> 00:19:36.120 William Cheng: Okay, so we wake up all of them both of them will try to compete, you know, for, for, for, for, you know, for, for the packet in Q2. One of them is going to win. And that will be the thread that will remove Q2. 139 00:19:36.660 --> 00:19:41.910 William Cheng: Remove a packet from Q2. And then what it will do is that it will simulate packer transmission by going to sleep. 140 00:19:43.170 --> 00:19:49.920 William Cheng: Okay, so over here at the picture. So to show you that it will go into Q to and pretty quickly. It will you know that this pack will go into S one 141 00:19:50.400 --> 00:19:58.650 William Cheng: So in this case, your simulator transmission of the packet at some point later at time t go to D one, that's when he was going to get rejected on the system. 142 00:19:59.880 --> 00:20:05.580 William Cheng: Okay, so therefore, in this case, you know, what is going to be the response time of this packet rather response. I'm going to be over, you know, 143 00:20:05.820 --> 00:20:11.730 William Cheng: Over here is going to be equal to one minus a one right over here. So this is going to be the time for the response time 144 00:20:12.600 --> 00:20:21.510 William Cheng: Okay, what about a service time right the service time is when you start servicing this packet. When you start transmitting this packet and then until you decide to reject this packet 145 00:20:21.900 --> 00:20:27.300 William Cheng: Okay, so therefore it's going to be d one minus the time that you start service, you know, for, for this particular package. 146 00:20:27.960 --> 00:20:34.860 William Cheng: Okay, it's okay, look at this picture to how to see how these things move around inside the system and then how to compute all these different values. 147 00:20:35.610 --> 00:20:44.670 William Cheng: That are. So, by the way. The service times a little confusing. Other two kinds of service time I'll one is the surface time requirement for the packet. And that's going to be specified in milliseconds. 148 00:20:45.060 --> 00:20:51.330 William Cheng: The other one is the measure of service time over here. So what are the measures. Over time, the major service time is that is the time difference 149 00:20:51.540 --> 00:21:00.180 William Cheng: Between the time that the server. The packet leave this is them minus the time that the time that packet the packet is a star transmission 150 00:21:01.050 --> 00:21:12.810 William Cheng: Okay, so the packet start transmission at this time. And then at time t one over here that the package is going to finish transmission. So therefore, the, the time difference over here is going to be the package transmission time or the packets service on 151 00:21:14.280 --> 00:21:18.240 William Cheng: Okay, so there will be the measure service time. And then again, that will be different from 152 00:21:18.600 --> 00:21:25.680 William Cheng: The, the service type of the packet which is the which is the requirement for that packet. So with this packet needs to get transmitted it needs to take one millisecond or something like that. 153 00:21:25.890 --> 00:21:33.750 William Cheng: But in the end, when you try to measure the actual service time it's going to have microsecond resolution, because the clock that we use has Microsoft microsecond resolution. 154 00:21:34.560 --> 00:21:41.460 William Cheng: Okay, so one way to think about is that the specification over here. It's going to for service time is going to be in the in the unit of my own millisecond. 155 00:21:42.060 --> 00:21:48.570 William Cheng: While the, the actual service time that's measure is going to have a, you know, it's going to have a resolution of microsecond 156 00:21:49.470 --> 00:22:01.290 William Cheng: Net. So similarly, the response time over here. It's going to also have microsecond resolution, the arrival time the departure time since we're reading a clock. They're all measure value and they all have microsecond resolution. Yeah. 157 00:22:03.660 --> 00:22:06.210 William Cheng: All right, one more packet, you know, 158 00:22:06.930 --> 00:22:18.840 William Cheng: Right over here. So here's packet number to over here. Right. And then at this time a package. Number one is being serviced by server number one over here. So server. Number one is busy. So in this guy server. Number two, what is it doing what is sleeping. 159 00:22:19.350 --> 00:22:27.390 William Cheng: So in this case packet number two is going to arrive over here and this one require five tokens over here. Okay, so therefore this packet the packet number to over here. 160 00:22:27.660 --> 00:22:38.460 William Cheng: So, by the way, q1 and q2. They are accused of packets. Okay. There are not a cure threats. Okay, in this case, we only forth to address the lab that the other the packets, where the tokens, where the silver thread. 161 00:22:39.180 --> 00:22:42.810 William Cheng: So, so we don't really have a cure through as the queue of threads is in the new tax. 162 00:22:43.560 --> 00:22:50.100 William Cheng: Write the music has a meat ax. Q. It's sort of invisible from you. Okay, the way we sort of thing about me is that the new taxes. 163 00:22:50.820 --> 00:22:58.260 William Cheng: So so so what we can do that, we can put the entire data structure over here inside of civilization box. Okay, so this will be the serialization box right here. 164 00:22:58.500 --> 00:23:06.720 William Cheng: Okay, so therefore there's a mute tax in front of it and the new tax Q is a queue of threats. Okay, q1 and q2 over here. They're cute packets 165 00:23:07.290 --> 00:23:14.910 William Cheng: Okay. And we also have a condition variable condition rebel over here. So there's a condition verbal cue that condition variable Q is also a queue of threats. 166 00:23:15.540 --> 00:23:21.150 William Cheng: You guys again don't get confused, you know, between the queue of threads versus the cure packets. Yeah. Alright. 167 00:23:21.930 --> 00:23:28.710 William Cheng: So packet number two. I'll be here when I arrived. It doesn't even have token. So he's gonna sit inside Q1 over here waiting for tokens to be arrived. 168 00:23:28.920 --> 00:23:36.420 William Cheng: And then you know why know we're always going to be the the the the the the data into token arrival, Ray. So eventually, or sooner or later you're going to get any 169 00:23:36.660 --> 00:23:43.350 William Cheng: You know, okay, so this picture. So to show you that when it you know when another tokens over here is going to go to five lab is that we're going to wake up. 170 00:23:44.100 --> 00:23:52.860 William Cheng: What will happen is that we're going to, we're going to remove this packet from Cuba moving into Q2. And we also going to consume five five tokens. So, therefore, this guy is the Kotaku got zero 171 00:23:53.940 --> 00:24:01.920 William Cheng: OK, and now why is this, this part this packet going to cue to you will wake up a server threat. Right. So again, what do you what do that you do a piece of condition broadcast 172 00:24:02.160 --> 00:24:12.480 William Cheng: Since as one over here is not sleeping inside the condition variable queue and only as to is sleeping. Is that a condition verbal cues. So in this case, when you call Peter condition broadcast only as to okay woken up 173 00:24:13.260 --> 00:24:22.290 William Cheng: Okay, so therefore when as to start executing code again it will remove a packet from Q2 moving into S two. And then what do you do that it was simulate the transmission of that packet 174 00:24:22.470 --> 00:24:29.520 William Cheng: So we here at this time over here, it will start transmitting that packet Enos to and then you know at that time you go to D to 175 00:24:29.940 --> 00:24:39.810 William Cheng: That's when this packet will get rejected. OK. So again, you can compute the, the response time of this particular package you can measure the service time and you have you have major all the other times. Okay. 176 00:24:40.590 --> 00:24:47.970 William Cheng: All right. You can also have another packet arrival. We hear it right over here package. Number three arrival. We here at the time of this particular package arrival 177 00:24:48.480 --> 00:24:55.290 William Cheng: P one has already left the systems, a server one over here, it's gonna be, it's gonna be, it's gonna be available. 178 00:24:55.650 --> 00:25:05.640 William Cheng: Okay, so therefore you know what package three arrived will be here at this one required to tokens over here. So he needs to wait for two tokens. Right. I wanted to get to tokens, you will get moving to Q2. 179 00:25:06.150 --> 00:25:12.570 William Cheng: So at this point you will wake up a server thread number one by calling Peter finishing broadcast and then it will start transmitting that packet 180 00:25:12.930 --> 00:25:23.520 William Cheng: Okay, so in order for you to sort of figure out, you know, whether you are doing the simulation correctly or not. You need to be able to draw a timeline like this understand exactly when you know 181 00:25:24.030 --> 00:25:31.230 William Cheng: Understand exactly when some events supposed to happen okay when some event supposed to happen. You got to make sure that it happened immediately. 182 00:25:32.220 --> 00:25:42.870 William Cheng: Okay. Otherwise, you know, you have a bug in your code, right. So for example, if I put a packet into Q2 and the q2 over here has one packet and one of the servers thread over here is available. Why not case, what should happen. 183 00:25:43.470 --> 00:25:52.110 William Cheng: Well, so in this case your flesh you wake up the server threat and when the services are running again you need to remove this packet and start transmission. Okay, how long should I take 184 00:25:53.070 --> 00:25:59.250 William Cheng: Well, I don't know, okay, it really depends on you know how fast your machine is because we're simulating all this time in real time. 185 00:26:00.000 --> 00:26:11.370 William Cheng: Okay, so therefore, in this case, you know when our third wakes up, you know. So, so what happened is over here is that you are called Peter condition broadcast when you go, people can do broadcast. This was going to get picked up moving to the meat AX queue and then 186 00:26:11.820 --> 00:26:18.930 William Cheng: You know your thread over here publican copies. I'm it has unlocked when you copy service unlock another thread is going to come into the SU ization box. 187 00:26:19.110 --> 00:26:24.300 William Cheng: And then what he would do is you have to evaluate the guard the guard is true in this case is going to perform 188 00:26:24.660 --> 00:26:36.720 William Cheng: The command sequence. So in this case, what it will do is that he will. He will dq dq a packet from Q2 and then moving outside in moving outside moving outside of the serialization box. 189 00:26:37.830 --> 00:26:45.510 William Cheng: Okay, and then he will unlock the new types over here and then now you know the the server threat will be able to transmit a packet. So what it will do is that it will inspect the packet 190 00:26:45.750 --> 00:26:52.560 William Cheng: Look at the service time in milliseconds, multiply that by 1000 and then call you sleep on that particular time. 191 00:26:54.420 --> 00:27:01.500 William Cheng: Okay, so, so, so, okay, you need to understand exactly how this thing works. And if you're confused about how it works. Feel free to ask me questions. Yeah. All right. 192 00:27:03.750 --> 00:27:09.600 William Cheng: All right. Are there are two different modes for the simulation and one of them is called the deterministic mode and the other one. 193 00:27:10.800 --> 00:27:11.370 William Cheng: See 194 00:27:16.770 --> 00:27:24.690 William Cheng: Okay, so one of them is called a deterministic ma. So it's deterministic again doesn't mean that's repeatable. All it means is that the inter arrival time 195 00:27:25.050 --> 00:27:32.760 William Cheng: Which is one overland so that the packet into arrival time. It's a fixed value. Okay, and also the token remote requirement for every packet is fix 196 00:27:33.150 --> 00:27:41.370 William Cheng: The spec. Use the the the notation capital P to represent that. And the service time is known as one overview. And again, that value is fixed. 197 00:27:41.670 --> 00:27:50.400 William Cheng: Okay, so in the deterministic mo all these three values are fakes in the trace driven mo every packet headers own into arrival time token requirement service. 198 00:27:51.000 --> 00:27:57.600 William Cheng: Okay, so all those three values, you know. So what do you need to do that, you need to read a you need to input file called the chase spec. 199 00:27:58.380 --> 00:28:04.500 William Cheng: Chase spec file right because you're doing trades driven simulation, you're going to read a trace specification file. 200 00:28:05.070 --> 00:28:14.370 William Cheng: So that will be the file, it's kind of looked like your warm up warm up ones input file every line specify the packet. So over here, again, for every packet is going to be three numbers. 201 00:28:14.760 --> 00:28:30.780 William Cheng: One of them is the the entire arrival time in the unit of millisecond, and then the total the total requirements over here is going to be an integer. Yeah. And finally, the service time is also going to be an integer. And that will also be in, you know, in the unit of milliseconds. 202 00:28:31.950 --> 00:28:43.590 William Cheng: Alright, so every line over here only contain you know three numbers and the numbers are separated by either tab or space or a combination of number of happens tabs in space. Okay, so the input is a little different. 203 00:28:44.100 --> 00:28:50.730 William Cheng: From the one more point input. Okay, one more input all the fields are separate by tabs in this case is a little different. Okay. 204 00:28:51.480 --> 00:28:58.050 William Cheng: All right, so you need to implement these for child threads. One is called the packet arrival threat or the packet threat and the other one's got a token, the positive 205 00:28:58.320 --> 00:29:05.490 William Cheng: Or the token token threat and I'm going to end up with two servers as one and as to these threats work together by sharing variables. Yeah. 206 00:29:06.660 --> 00:29:15.570 William Cheng: Alright, so let's take a look at the pseudo code for these, you know, four threads at a very, very high level pseudo code for both the packet thread a token. So they're very similar 207 00:29:16.140 --> 00:29:22.590 William Cheng: Okay, so what they will do is that they will stay in an infinite loop. Okay, and what they will do is that they will sleep for the right amount 208 00:29:23.160 --> 00:29:29.430 William Cheng: Okay, so to get the right amount you need to read the spec to find out what the right amount is right and that will happen is that when they wake up, then go to generate something 209 00:29:29.670 --> 00:29:33.570 William Cheng: Okay, for the Pakistani they will generate a packet for the token thread, they will generate a token. 210 00:29:34.140 --> 00:29:47.280 William Cheng: OK, and then they will add a packet to to talk about the theater or if you're the tokens, where you add a token to talk about the filter. OK. And then, and then you implement all the rules to move the packet around, all that kind of stuff, but at a high level. They look exactly the same. 211 00:29:48.990 --> 00:30:00.000 William Cheng: Okay, so, so okay he need to understand that at a high level, the token thread and packages. They're very simple they sleep they create something they add something to the system. And then they go back to sleep again. 212 00:30:01.800 --> 00:30:04.950 William Cheng: Okay, so that's what you should then and now, everything else is details. 213 00:30:05.340 --> 00:30:11.160 William Cheng: Right. It's a detailed implementation. Okay. Similarly, at a very high level of pseudo code. What would the service or I do right 214 00:30:11.370 --> 00:30:19.590 William Cheng: So at the beginning of your the server threat they need to wait for work right if Q2 is empty over here. They have no work to do. Right. They have no work to do. Then they go to sleep in a condition variable. Q. 215 00:30:20.040 --> 00:30:27.810 William Cheng: Okay, so therefore, at the very, very high level there, you know, the code is like this. Again, they stay in an infinite loop over here work on something forever. 216 00:30:28.050 --> 00:30:40.620 William Cheng: Number one is that they wait for a packet appearing Q2 and then they will remove the packet from Q2. I mean, some people actually do the simulation incorrectly, they will leave the packet in Q2. Why they are transmitted. Again, that's totally wrong. 217 00:30:41.910 --> 00:30:49.140 William Cheng: OK, so maybe you have maybe your W student that you simulate this kind of stuff. You know, you know, W class again there's simulation is different from our simulation. 218 00:30:49.350 --> 00:30:57.660 William Cheng: Okay, for our simulation, you have to remove the packet from Q2 and take it into the possession of your server threat and then you transmit a packet 219 00:30:59.310 --> 00:31:06.030 William Cheng: OK. So again, the server threat you know all the, all it does is to wait for packet. Remove the packet and transmit the packet 220 00:31:07.260 --> 00:31:11.700 William Cheng: So that's all they do. Okay, again, the rest are all details right your implementation details. Yeah. 221 00:31:13.110 --> 00:31:23.820 William Cheng: Alright, so let's take a look at, you know, the packet filter over here at the packet thread you need to transmit and packet or you need to generate and packet, so not not not not not transmit that need to generate an impact. 222 00:31:24.150 --> 00:31:31.170 William Cheng: So therefore you can execute the loop and times right over here, even though I sort of draw the infinite loop over again you that's a very high level. 223 00:31:31.710 --> 00:31:36.600 William Cheng: But in reality, you could you should only execute that loop and most n times they're 224 00:31:37.020 --> 00:31:48.150 William Cheng: All right. So in this case, every iteration over here, you need to sleep for an interval trying to match a given inter arrival time. Okay, so in the deterministic mo interactive times one over lambda, again, you need to 225 00:31:49.560 --> 00:31:54.960 William Cheng: So so so it's going to be one over lambda up. Okay. And I think somebody asked that in 226 00:31:55.980 --> 00:32:07.980 William Cheng: In the last lecture about you know that that this the interval time business that the interval time. So, so if the interrupt. What time of year is one over lambda, it doesn't mean that you generate a packet everyone overland up 227 00:32:09.150 --> 00:32:13.620 William Cheng: OK. So again, for our for our simulation. Over here we have slightly different, you know, different definition. 228 00:32:14.220 --> 00:32:26.760 William Cheng: If the inter arrival time is one overlander. That means that if you know when the previous package has arrived. Okay, then we know that the next package is supposed to arrive at the previous packages arrival time plus one over lambda 229 00:32:28.050 --> 00:32:35.730 William Cheng: Well, so what's the difference. The difference is that you know when a partner supposed to arrive, maybe you will arrive three seconds later maybe will arrive, you know, five seconds late 230 00:32:36.390 --> 00:32:42.750 William Cheng: Okay, so, so, so, you know, you have to wait for the package to arrive first and then you will know when is the next package. Suppose, all right. 231 00:32:43.290 --> 00:32:52.530 William Cheng: Guys, okay. If the packet supposed to arrive at this time. Okay. As it turns out, they arrive. A little later. Then the next package arrived, one over lambda after this package has arrived. 232 00:32:53.880 --> 00:33:06.180 William Cheng: Okay, not you know you shouldn't have one over lambda to the original time when the Pegasus who arrived. Okay, so for our definition of the interval time. You only know when is the next package. Suppose arrived, when the current package has arrived. 233 00:33:07.410 --> 00:33:17.040 William Cheng: Okay. All right. So, so what you need to do, though, is that we need to go to sleep. You say, Well, how much should I sleep again. I need to look at this time, I need to find out when was the last package arrived, and then I need to 234 00:33:17.340 --> 00:33:23.700 William Cheng: Let one overlander to it. And now I need, I need. I know that the next packet is supposed to arrive at this time. And then I need to find out. 235 00:33:24.420 --> 00:33:29.610 William Cheng: You know, what is the current time right if the current time is here already. WELL, IN THAT CASE I DON'T CALL YOU SLEEP. 236 00:33:29.970 --> 00:33:39.450 William Cheng: Okay, but if the current time is right here. I shouldn't sleep or one over lambda i should sleep with this amount right there. The remaining time right because because the neck next packet supposed to wake up at this time. 237 00:33:41.070 --> 00:33:51.900 William Cheng: Or is it again. You have to implement this one correctly. Otherwise, your timings going to be completely off now. Right. So, so once you go to sleep you need to figure out how much asleep, and then when you wake up, you're going to create a packet 238 00:33:53.340 --> 00:34:07.110 William Cheng: Over here, it says you lock the new tax. OK. So again, you know, we're here, we're going to put the entire Token Bucket filter a standard out and the clock, all this kind of stuff, all you know under the, the, the, the protection of one new tax. 239 00:34:07.710 --> 00:34:14.610 William Cheng: And that's, again, this, this, you know this this exercise the a warm up to is not a new types exercise as a multi threading exercise. 240 00:34:15.030 --> 00:34:23.430 William Cheng: Okay, so therefore, don't get too fancy with them you tax. Right. Okay. So you'd like to be tags over here and then you include the package to q one over here and then 241 00:34:23.730 --> 00:34:30.660 William Cheng: If you know this package that you just add it turns out to be the only package the Q1 and now there's enough token insert token bucket. 242 00:34:30.870 --> 00:34:43.980 William Cheng: Then in that case you have to remove that packet from Cuba and moving to Q2 and then remove the right number of tokens want to talk about it. And then if Q2 was empty. Before you need to broadcast a cue to that empty condition to wake up the server threat. 243 00:34:45.300 --> 00:34:52.050 William Cheng: OK. So again, you're required to use piece or a commission broadcast. You are not allowed to use Peter condition signal. Okay, otherwise can do some points. Yeah. 244 00:34:52.860 --> 00:35:03.360 William Cheng: Right. So when this is all done right so so again look at a very high level pseudo you are you sleep and you generate a packet and then you do all this kind of stuff. And then you're done. And you go back to sleep again. 245 00:35:03.630 --> 00:35:07.350 William Cheng: Yeah, so therefore we're going to unlock the meetings over here and go back to sleep or the right back. 246 00:35:08.640 --> 00:35:12.870 William Cheng: Alright, so this is the the package where the toggle through it again, very similar. 247 00:35:13.890 --> 00:35:24.600 William Cheng: So the tokens are. We don't know how many tokens. We need. Okay. So, therefore, therefore, the way you think about is, I'm going to do forever in every iteration you sleep for an interval trying to match a given interval time 248 00:35:25.380 --> 00:35:32.940 William Cheng: And this then this so what what do I use the word inter token arrival time I'm distinguishing that between the entire arrival time for the packet 249 00:35:33.690 --> 00:35:45.810 William Cheng: Okay so so entertainment arrival time is one over our right. So, again, in order for you to figure out when is the next token supposed to arrive. You need to know when is the current when the current token has arrived. 250 00:35:46.230 --> 00:35:54.180 William Cheng: Yeah. So let's say that you try to the current token supposed to arrive at this time, but again you opportunities and waking up at a later time over here. So this is the time 251 00:35:54.390 --> 00:36:01.050 William Cheng: The token has actually arrived and then again you add one over our to it. And then this will be the time the next tokens supposed to arrive. 252 00:36:02.280 --> 00:36:11.880 William Cheng: Or is it again. You have to implement this correctly. Yeah. So when the token thread over here wakes up guys again he wakes up, it's going to be after you know after the time is supposed to supposed to supposed to arrive. 253 00:36:12.150 --> 00:36:20.700 William Cheng: And then at this point. What happened is that even allowed to be tags over here, increment the token count. Okay, so to increment to to implement the token, all you need to integer 254 00:36:21.090 --> 00:36:27.660 William Cheng: Right, because all that matters is the number of tokens that you have. So you don't need a linked list to implement you know all your tokens, because all the tokens are identical. 255 00:36:28.170 --> 00:36:33.750 William Cheng: Okay, so therefore you just have a token count over here, the token, the token bucket has a bucket depth. 256 00:36:34.200 --> 00:36:42.810 William Cheng: There. So this example the bucket death over here is equal to six. So when you implement a token. And now it's equal to seven token. Well, then the extra token will get thrown away. 257 00:36:43.320 --> 00:36:53.040 William Cheng: Okay, so, so, so, so, so over here. I guess terminology that we use is that we're going to get a token overflow overflow. It just is just going to disappear. So we still end up with six token. 258 00:36:53.520 --> 00:37:01.740 William Cheng: Now and then also when we add a token token bucket. We need to check the first packet in Q1 to see if now this packet has enough tokens. 259 00:37:02.400 --> 00:37:08.430 William Cheng: That if it does, we're going to remove this packet on Q1 edited Q2 and then reduce the number of packet over here. 260 00:37:09.300 --> 00:37:17.910 William Cheng: That equal to the token requirement for that particular packet there. And then again, or what we need to do that, we need to we need to Brock has the condition to wake up server threat that 261 00:37:18.360 --> 00:37:26.310 William Cheng: By the way over here to say that you're, you can, you need to check where the Q2 was empty before and it was empty before then you can broadcast a cue to not empty condition. 262 00:37:27.060 --> 00:37:33.240 William Cheng: To you really have to check whether to two is empty or now. Okay. So the answer is you don't really have to do that again. Because if these two up 263 00:37:35.190 --> 00:37:39.330 William Cheng: If it turns out that these two threads. You know that 264 00:37:40.830 --> 00:37:49.320 William Cheng: If it turns out that they are actually packet inside Q2, then that will means that s two, s one, they are both transmitting packets at the current time 265 00:37:50.100 --> 00:37:55.680 William Cheng: Okay. So, okay, you need to think about it. You need to sort of think about that a little bit as it should understand why is that going to be the case, there 266 00:37:55.800 --> 00:38:02.430 William Cheng: So as one. And so over here. Both of them are not in the condition variable. Q. What happens if you try to broadcast the condition. Well, nothing will happen. 267 00:38:02.910 --> 00:38:09.630 William Cheng: Okay, so therefore it's oh it's okay to always broadcast the condition because whenever you try to add a packet. If you want just broke has a condition. Okay. 268 00:38:10.740 --> 00:38:18.570 William Cheng: All right, and then we finished doing that, you're not to meet us go back to sleep for the right amount. I said, well then, so how does it tokens to I supposed to terminate. 269 00:38:19.590 --> 00:38:28.920 William Cheng: Okay, so for the Packers threat right when you finish generating impacted while they yourself terminate for the tokens way over here it says you must terminate. As soon as it's no longer needed. 270 00:38:29.760 --> 00:38:35.550 William Cheng: Okay, so you need to sort of figure out under what condition does the token through it doesn't need to generate any more tokens. 271 00:38:37.050 --> 00:38:43.260 William Cheng: OK. So again, if you can figure that out. We should start discussion in the class Google group which is me email, we should talk about this. Okay. All right. 272 00:38:44.280 --> 00:38:55.590 William Cheng: For the server threat. They also live forever over here. So again, what I need to do is that need to wait for work and then once they have work to do. They will simulate the transmission of a packet. OK. So again, what they will do is that they will lock the new tax. 273 00:38:56.160 --> 00:39:05.580 William Cheng: You know, stay in a loop to wait for Q2 to become an empty. So again, what does that look like, right. So again, this is the garden command right the first three land of the garden command is always 274 00:39:05.880 --> 00:39:11.280 William Cheng: Peaceful and new tax law. One night guard Peter condition. Wait. OK. So again, that's what you're supposed to do. Yeah. 275 00:39:12.000 --> 00:39:18.270 William Cheng: Alright. So as it turns out, if the guard is true, that means that Q2 is not empty, while he's in that case you would DQ a packet from Q2. 276 00:39:18.480 --> 00:39:25.530 William Cheng: And then you unlock them attacks. Right. So this way. Once a DQ the penguin Q2. It goes outside of the city or the civilization box. 277 00:39:25.740 --> 00:39:35.280 William Cheng: And now you can work on it, you know, in all your threat. So this guy is performing work over here. You're going to perform the work with the new tax unlocked. Okay, so you're going to sleep on an inter 278 00:39:35.880 --> 00:39:39.120 William Cheng: Sleep on an interval matching the service time of the packet 279 00:39:39.630 --> 00:39:50.010 William Cheng: OK. So again, the package, I should have a service time on it, and the service is going to be in a unit of milliseconds, you multiply that by 1000 and you call you sleep on it right though. That's all you have to do that. 280 00:39:50.850 --> 00:40:01.590 William Cheng: All right, and eventually when the packet is done over here, they, they need to store it away. You need to reject the packet. You just delete a packet. What you should do is that you should update the statistics and then after that you can delete the packet 281 00:40:02.130 --> 00:40:06.960 William Cheng: OK. So the idea here is that inside the packet the packets of data structure. We're going to start a bunch of information about 282 00:40:07.470 --> 00:40:17.970 William Cheng: You know, all these events that have happened as the pocket travel through the system. Okay. So, therefore, at the end when the packet is is going to get deleted right before that you can update all the statistics. 283 00:40:19.350 --> 00:40:26.070 William Cheng: Alright. So again, that's the that's sort of the death, whether you're supposed to handle statistic calculation. We're going to talk about that soon. Okay. 284 00:40:27.690 --> 00:40:40.440 William Cheng: All right, and also for the, you know, for the server threat. They also myself terminate as soon as they are not needed. OK. So again, that's part of the exercise for to figure out when are they gonna need again, feel free to discuss in the class, we will groups me email, etc. 285 00:40:42.630 --> 00:40:50.040 William Cheng: Oh I a packet can get dropped when should a packet good drop you know if the token requirement for robbing packet is too large. 286 00:40:50.850 --> 00:41:01.020 William Cheng: Okay, so if the token bucket that is going to be an example that we see over here. Be equal to six right whatever package arrived. It's package you know it's it's token requirements equals seven. 287 00:41:01.860 --> 00:41:04.950 William Cheng: Y in that case that packet will get stuck in Q1 forever. 288 00:41:05.670 --> 00:41:12.390 William Cheng: Okay, so therefore we must delete that packet, right, because this you know you would be, because if we include that packet into Q1, it will never leave you on 289 00:41:12.840 --> 00:41:18.990 William Cheng: Okay, so therefore we are required to drop packet and this particular package that get dropped because of this reason is known as a drop packet 290 00:41:19.380 --> 00:41:23.850 William Cheng: OK. So again, read the spec and the spectrum to tell you what are the definition of these different kind of package. 291 00:41:24.420 --> 00:41:32.070 William Cheng: The reason for that is that because some statistics, the only applicable to certain type of packets and so therefore you need to understand the terminology there. Yeah. 292 00:41:32.820 --> 00:41:40.230 William Cheng: All right. You can also have token being dropped right if the token bucket is Phil is completely full when token arrived and the token will get dropped 293 00:41:40.650 --> 00:41:48.930 William Cheng: So again, it's you know it's conceivable that token will get dropped you know all the time. Then again, there are lots of other requirements. Please read the spec. Yeah. 294 00:41:50.970 --> 00:42:03.390 William Cheng: Alright, so the program output must look like what's in the spec. Okay, you, you must now wait for the emulation to end before you print out your, your, your spec or so some people says, oh, you know what happens that 295 00:42:04.560 --> 00:42:06.060 William Cheng: If I tried to print out all these 296 00:42:06.360 --> 00:42:19.200 William Cheng: All these information on the fly. Some of the timestamp over here will be reversed. So what I will do is I will hold off all these events over here and then I will sort them when the simulation is over. Then when I print this out over here, they will all be in the sorted order. 297 00:42:19.860 --> 00:42:32.820 William Cheng: Okay, so you're not allowed to do that you don't end up losing a lot of points. Okay, you must produce these traces on the fly as these event happens. Okay, you got to make sure that the timestamp over here it's going to be an in a non decreasing order. 298 00:42:33.360 --> 00:42:37.230 William Cheng: Okay. Anytime that are flip, you're going to end up losing points. Okay. That means that you have bugs. 299 00:42:38.340 --> 00:42:46.200 William Cheng: Bunny. Oh, yeah. Alright, so here's the sort of print out your program before you start your emulation. You need to print out your imagination parameters. Yeah. 300 00:42:46.650 --> 00:42:53.610 William Cheng: So you need to print out all these lines, the immunization parameters, the number of packets to arrive. Right. That's the little end that I showed you before you need to print that out. 301 00:42:54.120 --> 00:43:01.740 William Cheng: Over here, it says you need to print Lambert equal to two. If minus t is not specified. Okay. So, which means that it minus t i mean don't don't don't 302 00:43:02.220 --> 00:43:12.360 William Cheng: Don't put this thing in the parenthesis. So if minus t is not specified that means that you are running the deterministic mo in the deterministic mode, the entire packet arrival time is going to be one over lambda 303 00:43:12.750 --> 00:43:20.850 William Cheng: Okay, so therefore you need to print out exactly what the value of land is. Yeah. And also, if it is not specify them is that you are in the deterministic Mo, you have to print this line. 304 00:43:21.150 --> 00:43:24.930 William Cheng: There. What if minus T specify what day you don't print these two lines at all. 305 00:43:25.890 --> 00:43:36.090 William Cheng: Okay, I don't really wanted to sort of write the printer for all different kinds of combinations of style or you're supposed to print right so that's why I write it this way. Right. So again, don't print them don't print this you know parenthesis if minus t is not specified 306 00:43:36.900 --> 00:43:45.240 William Cheng: They're all right. Are you should always print are and you're always putting capital be a bucket, the bucket that and then you only print p 307 00:43:45.510 --> 00:43:52.110 William Cheng: capital P over here. If you're in the deterministic mode, right. So that's the number of total required for every for every packet 308 00:43:52.410 --> 00:44:03.390 William Cheng: There. And finally, if minus T specify why, in that case, there's going to be a TS found and the key is is trace specification file. So in this case, yes. You say you should print t is equal to follow by the phone it 309 00:44:04.800 --> 00:44:08.550 William Cheng: Alright, so, so, so when you are simulation is about to start. You should print this out first. 310 00:44:09.390 --> 00:44:16.050 William Cheng: Okay. And then what you would do is so, so what happened is that you can actually do all these things before you start a simulation before you create any child threads there. 311 00:44:16.230 --> 00:44:23.280 William Cheng: And then what you would do is that you print out the first time over here and print out a time equal to zero simulation star. So, what you should do is that you should read the clock. 312 00:44:23.550 --> 00:44:29.070 William Cheng: Okay, there's a function that you're required to use. It's called get time of day. If you can get time of day, you're going to get the current time 313 00:44:29.610 --> 00:44:36.090 William Cheng: Okay, the current time over here will be known as your simulation star time. So again, if this is your timeline. This is your 314 00:44:36.390 --> 00:44:47.640 William Cheng: Simulation start time. So here's the star time over here, you need to store that into a global variable and then everything else that you print over here, you're printing the difference between the current time and the simulation star time. I mean, 315 00:44:48.450 --> 00:44:55.590 William Cheng: Okay, I shouldn't say the current time the event time every one of these lines over here correspond to event. Okay, so for every event. 316 00:44:55.950 --> 00:45:04.350 William Cheng: You need to read the clock and then you find out what the event time is you take that event time and you subtract from it the simulation start time and that will be the timestamp for your event. 317 00:45:06.000 --> 00:45:11.010 William Cheng: Alright, so please read the spec over here to find out exactly what events are every packet. You know, every 318 00:45:11.580 --> 00:45:17.640 William Cheng: Every normal packet supposed to have seven events. Yeah, you need to sort of find out what they are. Right, so I'm not going to go into too much detail. 319 00:45:17.850 --> 00:45:25.500 William Cheng: What I need to point out is that the time over here on the right hand side. On the left hand side over here, all these times are measured time 320 00:45:26.250 --> 00:45:33.030 William Cheng: Okay, so what does it mean that, what does it mean that they're measured time that that means that you read the clock. When you read the clock, you're measuring something right you're measuring time interval 321 00:45:33.420 --> 00:45:39.240 William Cheng: So in that case, all these values over here are measured. Now, the only thing that's not measured over here is going to be 322 00:45:39.600 --> 00:45:46.740 William Cheng: It's going to be the request the service time so you see a line over here it says P one beginning service s one 323 00:45:47.040 --> 00:45:53.850 William Cheng: Okay. And he says, requesting so much of service time. So this one you're requesting a certain number of milliseconds of service. 324 00:45:54.270 --> 00:46:05.010 William Cheng: Guys, and this guy is this number over here is not going to be a measure one. So this one can come from a trace file. Okay, can also come from, you know, so in this case, this number can also come from, you know, one over 325 00:46:06.210 --> 00:46:11.640 William Cheng: There. So again, when you get one over meal, you need to convert that into a millisecond. And then this is the number that you print 326 00:46:13.140 --> 00:46:20.850 William Cheng: OK, so the service. The other request the service time over here is always going to be in the unit, the millisecond right everything else over here has a resolution of a microsecond 327 00:46:21.240 --> 00:46:25.710 William Cheng: Okay, so therefore, in this line. If you look at the first line over here for p one p one arrived in 328 00:46:26.010 --> 00:46:38.880 William Cheng: In these three tokens, the inter arrival time. So what is the interval time. So in this case is going to be the measure into arrival time is going to be the timestamp difference between this line and the pre and the time when the previous packet has arrived. 329 00:46:39.900 --> 00:46:50.280 William Cheng: Okay, so when has a previous packet or right wasn't. This is the first packet. The previous packet arrival time to go to zero. So, therefore, in this case the inter arrival time for this package is going to be exactly this timestamp. 330 00:46:51.780 --> 00:47:00.210 William Cheng: Okay, what about packet number to over here packet number to over here arrived at this time. Let me declutter this right package number to arrive at this time. 331 00:47:00.540 --> 00:47:11.580 William Cheng: Okay. So, therefore, what is the interval type what the interval time is going to be the arrival of Apache to minus the arrival time a packet when when the package number one arrive packet number one arrive at this timestamp. 332 00:47:11.970 --> 00:47:18.480 William Cheng: There. So therefore, the interest of time has to be exactly the timestamp difference between this timestamp and this timestamp. 333 00:47:20.430 --> 00:47:24.360 William Cheng: OK. So again, my recommendation over here is that when he tried to store these timestamp, you need to store. 334 00:47:24.480 --> 00:47:33.300 William Cheng: Store them as integers, because if you don't install them integers, then you have to worry about losing precision, you need to worry about rounding, all that kind of stuff. Okay, so make sure you do it correctly. Yeah. 335 00:47:34.140 --> 00:47:39.660 William Cheng: All right, what else is over here eventually over here, I guess, at some point. 336 00:47:40.350 --> 00:47:46.860 William Cheng: P one is going to leave. Right. So we're going to continue over here data. Okay. Over here p one over here it departs from as one 337 00:47:47.100 --> 00:47:59.160 William Cheng: The service time over here. So in this case, it will be a measure service time is going to be the timestamp, this difference between this times that, and the timestamp, where p one starter service guy. So over here says, whoops, where to go. 338 00:47:59.970 --> 00:48:06.000 William Cheng: Okay, p one begin service at this time because service as one over here. So, this will be the time so I wouldn't begin service. 339 00:48:06.180 --> 00:48:11.820 William Cheng: And this will be the time to finish our servers. So therefore, the service time is going to be the difference between the two timestamps right 340 00:48:12.060 --> 00:48:16.050 William Cheng: What about the timing the system, the timing, the system is again the difference between two times them. 341 00:48:16.290 --> 00:48:22.380 William Cheng: This is a timestamp of when the packet leave this is them and then you need to subtract from it the the timestamp when the packet 342 00:48:22.620 --> 00:48:28.560 William Cheng: when when when p one arrived into the system. Again, there's a line for that you need to compute the exact difference the times that. Okay. 343 00:48:28.980 --> 00:48:36.390 William Cheng: All right, the rest of his dot dot dot over here. We don't know when it finishes over here, at some point, you need to print out a line to say emulation ends. 344 00:48:36.810 --> 00:48:44.640 William Cheng: Okay, so this is the time limitation. Once a widget emulation ads. Okay, my recommendation over here is that, again, you need to define exactly where emulation and 345 00:48:45.360 --> 00:48:48.510 William Cheng: What I would do is I will have the main threat print this one out. 346 00:48:48.840 --> 00:48:58.770 William Cheng: Okay, so your main so I will create all these for child threat, then you're going to join with all these for software when it's finished joining with all these four chapter is going to do some cleanup when it finished every, every part of the 347 00:48:59.430 --> 00:49:07.740 William Cheng: Simulation at that time your main so I should call you know get time of day. And then what it will do is that it will print out the timestamp for the time the simulation ads. 348 00:49:08.730 --> 00:49:14.940 William Cheng: So therefore, the timestamp for this line called emulation is going to be the total simulation time or total emulation time 349 00:49:15.240 --> 00:49:22.170 William Cheng: Right, because we know that at the beginning, over here, this time saying go to zero. In the end, if it ends at this time. Well, then this time is going to be the total simulation time 350 00:49:23.130 --> 00:49:28.140 William Cheng: Okay, so after you do that, you need to print the statistic and the statistic needs to be printed out by the main threat. 351 00:49:29.070 --> 00:49:35.100 William Cheng: Okay, so I'm going to sort of talk about these in a statistic a you know into average packet interval time average service time you, etc. 352 00:49:35.880 --> 00:49:44.160 William Cheng: OK. So again, it's very important to understand that the timestamp must have microsecond resolution and the measure time interval. My also have a microsecond resolution. 353 00:49:44.700 --> 00:49:56.490 William Cheng: Okay, well, you need to print out all these real values over here. I always get questions about what to do. Okay. The spec actually tell you exactly what to do. Okay. The spec says use percent dot six g imprint f 354 00:49:57.000 --> 00:50:07.710 William Cheng: For all these real values. Okay. Some people use present our six g over here and then they'll say, hey, that one doesn't look like it has six has significant figures, why should I do, what should you do 355 00:50:08.820 --> 00:50:16.680 William Cheng: What if the spec tell you to use this one, then that means that if it, if it prints out you know it's over here. It says, you know, the average derivative is 0.2 356 00:50:18.060 --> 00:50:23.910 William Cheng: Okay, you use percent are six g and print 0.2. Can I take points off of your, your printer. 357 00:50:24.750 --> 00:50:41.880 William Cheng: Well, no, right, because you follow this bag of the specs US US per se da si G and C library guarantee that this number will have six digit six digits of significant figures. Okay. So, therefore, when it printed 0.2 you need to understand why the 0.2 has 6666 significant digits. 358 00:50:42.990 --> 00:50:50.670 William Cheng: Okay, and not try to call it a different way of channels or print or something that you want some people insist that you want to print 2.0 point 2000000 359 00:50:52.500 --> 00:51:01.410 William Cheng: Okay, you don't have to do that if you use percent or 60 and what we need to do is to learn what it means to to print a percent or 60. OK. So again, there's a 360 00:51:02.430 --> 00:51:10.740 William Cheng: Warm up to FAQ, if you read that you don't even understand what's going on. Okay, well. So again, you know, follow the spec. Right. You cannot go wrong by following the spec. 361 00:51:12.060 --> 00:51:18.300 William Cheng: Alright so here again, you know, if we look at the the approval packet the packet over here. 362 00:51:18.720 --> 00:51:24.180 William Cheng: It's going to get generated about a packet arrival through. So the vertical axis overhears time. So as I'm time of 363 00:51:24.420 --> 00:51:36.900 William Cheng: Arrival threat. It's going to wake up. He's going to create the packet is going to, you know, the puck is going to go into Q1 and then we get removed from Q1 edit to Q2 and then remove on cue to begin service as one or two and leave service as one, it has to 364 00:51:37.320 --> 00:51:43.620 William Cheng: Okay, so what you're required to do that. There are seven events over here 1234567 365 00:51:43.830 --> 00:51:53.820 William Cheng: For every one of these events, you need to remember what time that event happened. And you also need to print a line in the output. So again, respect to find out you know what exactly what you're supposed to pray now. 366 00:51:54.300 --> 00:51:56.700 William Cheng: Alright, so, so again. So this guy's. What you will need to do is that 367 00:51:57.030 --> 00:52:03.780 William Cheng: You need to create a packet data structure just like a warm up one, you have a transaction data structure and now you need to design a packet data structure. 368 00:52:03.990 --> 00:52:10.410 William Cheng: Right. So what you're going out of pocket data structure. Well, you should have seven timestamps to store all these measure timestamps 369 00:52:10.980 --> 00:52:17.940 William Cheng: Okay, so what I will do is that I will get I will store timestamp in the, you know, in the data structure called struck time though. 370 00:52:18.480 --> 00:52:27.000 William Cheng: OK. So again, that's the data structure that has two parts. One is number of seconds. The other one is number of microseconds. And then you can call a bunch of function to manipulate these kind of timestamps 371 00:52:27.270 --> 00:52:32.400 William Cheng: Okay. So I think in the in the warm up to FAQ to sort of show show you what function, you will use that 372 00:52:32.880 --> 00:52:40.290 William Cheng: You also need to store the packet specification, such as the specified interval. Time to specify token requirement and especially 373 00:52:40.740 --> 00:52:52.620 William Cheng: The service time. OK. So again, in the deterministic mode. This is one over lambda in the unit of milliseconds. And then the service time is going to be one over mew in the unit of milliseconds. 374 00:52:53.040 --> 00:53:00.510 William Cheng: The total requirements just capital P. Okay. In the trace driven mode, all these three information. They come from one line inside the trace file. 375 00:53:01.620 --> 00:53:10.110 William Cheng: Okay. So, therefore, you know, it sort of shows you how you should, how we should create a package. You should read an input line from the chase file to create a package if it turns out you are nine to trace 376 00:53:10.320 --> 00:53:16.230 William Cheng: Trace driven. Oh, well, in that case, you just feel that data structure with one overland a capital P and also one over me. 377 00:53:18.180 --> 00:53:31.050 William Cheng: OK. So again, this should give you some idea of how you should write your program. Okay, so every packet correspond to one lie. You know, one line the input file or just use the global variable to get one over lambda one of them human capital P now. 378 00:53:31.890 --> 00:53:43.230 William Cheng: Alright. So again, these values over here. They are the package specification. They are not measure value, you know. So again, measure values when the computer from reading the clock value that 379 00:53:44.310 --> 00:53:52.380 William Cheng: Oh I so somehow can needs to be exclusive on certain statistics again read the spec. You know, so to find out exactly what's going on. If you have questions, send them to me. Okay. 380 00:53:52.650 --> 00:54:01.740 William Cheng: I want to briefly talk about measuring the computing the statistics. Okay, so, so, so, for example, the average service time. Okay. How do you compute the average service time right 381 00:54:02.310 --> 00:54:12.960 William Cheng: So in this case, you know, here's the average time interval. Okay, if there are over here. I use an over here. If there are any samples over here, you should add water sample and divide by and then you get the average 382 00:54:14.250 --> 00:54:24.300 William Cheng: Okay, so in this class right when the computer average and the third time interval you edible time interval you divided by n, that's going to be the the the the the the average. Right. So yeah, you need to do this very, very carefully. 383 00:54:25.050 --> 00:54:36.810 William Cheng: You know, and make sure that they're completely correct there. There's a weird statistics know as the average number of packets at a server. Okay, what is the average number of pocket a server. Well, you should think about is that at the best case. 384 00:54:37.860 --> 00:54:41.850 William Cheng: There. So if the server is always busy, the number of packet at the server should be one. 385 00:54:43.140 --> 00:54:50.160 William Cheng: Right, if the server is always busy. That means that, you know, anytime that the server, you see one packet in there. Okay. So, therefore, you know, this number can be a most one 386 00:54:50.790 --> 00:54:55.980 William Cheng: What if the server is never busy. Well, in that case, the average number of packet at a server is going to be equal to zero. 387 00:54:56.610 --> 00:55:05.460 William Cheng: Okay, so therefore this statistic is going to be a number between zero and one. As it turns out, there's another way to interpret this one. This is going to be the fraction of time the server is busy. 388 00:55:06.330 --> 00:55:13.140 William Cheng: Okay. So, okay, if the server is always busy. Well, then in that case the fraction is going to equal to one if the server is always not busy while then fractions going to be go to zero. 389 00:55:13.380 --> 00:55:23.940 William Cheng: Right. So if you look at the pipeline over here, the server can be busy or not busy so less the day when equal to zero, that means not busy when equals two, one, that means busy. Well, then in that case, you know, the other the other the 390 00:55:24.660 --> 00:55:30.510 William Cheng: Diagram or look like at the beginning of the service not busy and then it become busy and then become not busy and busy in our busiest etc. 391 00:55:31.080 --> 00:55:44.970 William Cheng: Okay, so if we add up the area under this curve and divided by the total simulation time we're going to get the average number of the average number of packet at the server. Okay. We also going to get the fraction of time the server is busy. 392 00:55:46.470 --> 00:55:52.830 William Cheng: OK. So again, all you have to do is to add up. Now, all the time, the server is busy divided by the total simulation time 393 00:55:53.700 --> 00:56:02.220 William Cheng: Guys again look at the picture over here and try to understand your why why that will be the case. Well, another statistic is called the average number of packet at Q1, or Q2. 394 00:56:02.730 --> 00:56:07.080 William Cheng: So q1 q2 is a little more complicated, right, at some point, the, the queue length equal to zero. 395 00:56:07.290 --> 00:56:12.060 William Cheng: And it goes up to why. And then it can go up to two and it could go down, back to one and outbound to zero. 396 00:56:12.270 --> 00:56:22.170 William Cheng: And then it will go back up to one after to up to three and then go to do so. So that. So again, it's like accounting Center for Digital after down like crazy. Okay, so what is the average number of pocket acuity. 397 00:56:23.340 --> 00:56:33.240 William Cheng: Okay. So in this case, again, the analogy the Agile view is very similar to the server. The average number of packet. A Q1 is the total area under the curve divided by the total simulation time 398 00:56:34.140 --> 00:56:41.340 William Cheng: Okay, how do you know that that that's going to be the case. Right. So again, you need to analyze this very, very carefully to sort of understand that that's exactly correct. Yeah. 399 00:56:41.820 --> 00:56:49.380 William Cheng: Alright. So again, I'm not going to go into detail. I'm just just asked you to compute the area under the curve. So how do you compute the area under the curve for this curve okay to go from zero to one, one to do 400 00:56:49.680 --> 00:56:56.550 William Cheng: So if you think about it that way it's gonna be very difficult to compete. Right. So you need to say, you know, you add up one over here, multiply by the duration of time. 401 00:56:56.760 --> 00:57:02.490 William Cheng: And then you need to multiply the duration of the time I use one multiple iterations. And that's how you compute the area under the curve. 402 00:57:03.090 --> 00:57:06.570 William Cheng: Okay. As it turns out, there's another way to, to, to compute the area under the curve. 403 00:57:07.200 --> 00:57:12.390 William Cheng: If you look at the first one over here. What is the waiting time in Q1 for the first packet 404 00:57:12.810 --> 00:57:21.570 William Cheng: Okay, the first packet over here, enter to win at this time. When did they leave or they leave when this one go from two to two one. Okay. So, therefore, the first packet over here. 405 00:57:22.170 --> 00:57:24.960 William Cheng: You know, the, the time that is spent in Q1 is actually equal to this. 406 00:57:25.740 --> 00:57:34.200 William Cheng: Okay, what about a second packet. A second packet arrive at this time and then leave at this time. So the second packet over here, the time that is spent in Q1 is actually horizontally this way. 407 00:57:35.160 --> 00:57:46.980 William Cheng: Okay, so therefore the area under the curve over here is going to be the time that each package spent inside IQ and if you add up all the time. All the participants IQ, then you're going to get the total area under the curve. 408 00:57:48.390 --> 00:57:59.010 William Cheng: Okay, so by simply adding the time every packet spent inside Q1 and then you got to get the total area under the curve. Okay. And then you can divide by the total simulation time you're going to get the average number of packets Q1. 409 00:58:00.240 --> 00:58:08.280 William Cheng: All right. Okay. Finally, there's a standard deviation. That's the square. Okay, so how do you can do the standard deviation. Right. So if you take a statistics class. 410 00:58:08.730 --> 00:58:20.160 William Cheng: There are two kinds of various. So, by the way, the standard deviation is the square of the variance. Okay, and the various is the average of x squared minus the average of x would do with a square over here. 411 00:58:20.880 --> 00:58:27.000 William Cheng: Go so average over x over here, we saw that already over your how to compute average of x, right. So what about the average of x square 412 00:58:27.240 --> 00:58:38.820 William Cheng: What average of x squared here is that instead of computer instead of taking x one plus x two, all the way to X end divided by n. So that will be the average of x, their average of x squared is that you square return 413 00:58:40.650 --> 00:58:48.000 William Cheng: Now, so there. But what you should do is that you should compute the average or square, he should also use the same technique over here to compute the average of x square 414 00:58:48.270 --> 00:58:54.930 William Cheng: And then when you're done, you simply subtract them using average of x square Avenue x squared minus the square of the average 415 00:58:55.860 --> 00:59:02.130 William Cheng: Okay, so this will give you the variance. And then what you do is that you take, you take the square with the variants that you got to get the standard deviation 416 00:59:02.760 --> 00:59:08.520 William Cheng: Okay, so in this case the variants that you. So as it turns out, if you take us. This is cloud. There are two kinds of the various 417 00:59:08.700 --> 00:59:18.210 William Cheng: One is called population variants. I can't remember what the other one. The other one is, but you are required to to compute the population various okay so therefore you're supposed to use this equation. 418 00:59:19.440 --> 00:59:27.780 William Cheng: Alright. So again, if you go to search stuff on the internet, you're gonna get different equation that will be wrong okay for our class, we have to compute the population various yeah 419 00:59:30.300 --> 00:59:38.730 William Cheng: Alright, so the rest of it. I kept going to skip them. So if you are new to multi threading. If you're new to processes and threads and all this kind of stuff. 420 00:59:39.120 --> 00:59:45.150 William Cheng: You should try out some of the codes that we talked about in the class. Okay, so in the discussion section. 421 00:59:45.930 --> 00:59:50.730 William Cheng: Though a web page. They sort of show you the code for a lot of these you know policy files over here. 422 00:59:51.000 --> 00:59:55.890 William Cheng: Okay, so if you're new to them what you should do is that you should run them, you should compile them, you should run them. 423 00:59:56.190 --> 01:00:05.520 William Cheng: Look at them all these code over here. They're all very, very short, some of them. We already talked about that in in the lectures. So you should run them to to make sure you understand that. 424 01:00:06.090 --> 01:00:18.270 William Cheng: Okay, each one of these code over here to demonstrate a very tiny idea and later on we try to write a bigger program I warm up to you're putting all these ideas together. So if you don't understand the visual ideas and he tried to put them all together, you can end up with a lot of bucks. 425 01:00:19.320 --> 01:00:27.960 William Cheng: Okay, so therefore, my recommendation is that, you know, right now, you still have time right you know you're at the beginning of warm up to you should play around with these code over here, compile them. 426 01:00:28.320 --> 01:00:33.930 William Cheng: You know, and run them under the debugger to understand what they do. And if you don't understand what they're doing over here again send me email. 427 01:00:34.500 --> 01:00:36.870 William Cheng: Okay, and then we can talk about in the cost of Google Maps era. 428 01:00:37.260 --> 01:00:47.220 William Cheng: Yeah. So there are lots of code over here. I'm not going to go over them. Right. So again, some of them already see that in the lectures over here and something that we haven't talked about it. So again, make sure you understand all these co 429 01:00:47.730 --> 01:00:50.730 William Cheng: You know, before you you I guess he 430 01:00:51.180 --> 01:01:01.830 William Cheng: Not know you actually know enough to actually implement warm up to especially that the simulation part. Okay. I think everything we covered to lecture five should give you enough stuff to finish the simulation for warm up to 431 01:01:02.700 --> 01:01:12.900 William Cheng: Okay in lecture six wouldn't talk about how to how to how to control C and then you can actually finish the entire the entire warm up to. Okay. All right. I'm going to stop right here. So, 432 01:01:14.070 --> 01:01:15.810 William Cheng: If you have questions, feel free to send them to me.