WEBVTT 1 00:00:02.340 --> 00:00:16.199 William Cheng: Okay, this is part two of lecture 10 in part one, we, you know, we talked about the street thread implementation of new tax law and it has unlocked. So now we're going to take a look at the 2 00:00:17.070 --> 00:00:27.990 William Cheng: Make it a more, you know, interesting, make it more complicated by introducing the second CPU, we are still not allowing the interval contacts. Right. So in this case, will completely in the right context. Okay. 3 00:00:28.860 --> 00:00:32.790 William Cheng: So, so the question is, I know, here's a, here's a new tags. How do you implement a new text. Okay. 4 00:00:34.590 --> 00:00:43.020 William Cheng: All right, so. So one thing that I just want to point out that, you know, when you have multiple CPU the switch code that I just show you it doesn't work anymore. 5 00:00:43.680 --> 00:00:48.270 William Cheng: Because, you know, we haven't really talked about, you know, we have multiple CPUs. How many monkeys do you have 6 00:00:48.600 --> 00:00:58.770 William Cheng: Do you have only one wrong key or do you have multiple reviews, you know, maybe you want one ranking for every CPU that's possible. Now, and also the other part part of this code that we 7 00:00:59.280 --> 00:01:04.560 William Cheng: That we really, you know, didn't really address is that will you teach yourself on the monkey. What is the wrong key was empty. 8 00:01:05.250 --> 00:01:12.600 William Cheng: Okay, if the monkey was empty in the queue that you're going to get a null pointer that if you try to you know go know pointer, right arrow something you'll get a segmentation ball. 9 00:01:13.170 --> 00:01:22.650 William Cheng: So in that case doesn't really work guys so, so, so I switch. It's sort of an interview. It's kind of a temporary code. So later on we did all we have to address all these issues. 10 00:01:23.550 --> 00:01:30.030 William Cheng: So right now, so don't assume that you know that this kind of words and we're going to sort of focus on the multi CPU issue. Yeah. 11 00:01:30.480 --> 00:01:39.990 William Cheng: So one thing that we want to do is we want to make sure that whenever you try to DQ a thread on the wrong key. There's always something to DQ right so this way. Next day over here will never be 12 00:01:40.260 --> 00:01:48.360 William Cheng: The next over here will never be no oh we can also think about the case where the wrong Q, you're going to have multiple run queue. So every CPU is going to have their own rank you 13 00:01:49.170 --> 00:01:56.880 William Cheng: Yeah, so in that case to make our life simpler. We're going to assume that you know for every CPU, there's going to be a threat, called the idle threat. 14 00:01:57.210 --> 00:02:03.510 William Cheng: OK, so again this is that has nothing to do our kernels Americano Simon has an idol process and the thread is that a process called idols that 15 00:02:04.050 --> 00:02:11.880 William Cheng: So this one is, I don't think so. This, I don't think it doesn't do anything. Okay, so you can create a thread that does nothing. Right. So this is what the first procedure for this doesn't look like 16 00:02:12.330 --> 00:02:17.340 William Cheng: It goes into an infinite loop and then what it will do is it will keep calling yield to give them the CPU. 17 00:02:17.940 --> 00:02:23.490 William Cheng: Okay, so, so this threat. All it does is give up CPU. So how do you give out the CPU you add yourself. 18 00:02:23.700 --> 00:02:30.330 William Cheng: So, so when your thread is running than the current threat. It's going to be yourself. You add yourself to the run queue and you call threat switch to give up the CPU. 19 00:02:30.960 --> 00:02:32.400 William Cheng: Okay, so this could actually work. 20 00:02:32.910 --> 00:02:41.520 William Cheng: Because if you think about if the run queue over here has some other threads that are sleeping, the wrong queue. So in this case, if you add yourself to the wrong key, you're gonna you're going to go to the end of the run queue. 21 00:02:41.700 --> 00:02:44.760 William Cheng: And when you cause stress, what you're going to give a CPU to the first of all right here. 22 00:02:45.420 --> 00:02:53.790 William Cheng: Okay, what is the monkey is empty. Okay, so when you run this code at the run queue is empty over here. When you call and Q, you're going to add the current thread itself to the head around you. 23 00:02:54.000 --> 00:02:58.920 William Cheng: So now it looks kind of weird, right, because your thread is running. Is that a CPU. It's also sitting at the head of the wrong you 24 00:02:59.130 --> 00:03:09.150 William Cheng: Know, so when you call thrush, which will happen, right. So again, if you examine the code for threats switch very, very carefully, you will notice that if I start doing something like this. I'm going to end up giving the CPU to to yourself. 25 00:03:10.170 --> 00:03:14.070 William Cheng: Okay, so, so even though when there's no other thread around Q this code will 26 00:03:15.180 --> 00:03:19.350 William Cheng: Still work because it will end up the idols. I will keep giving the CPU to to sell. 27 00:03:19.980 --> 00:03:21.750 William Cheng: Okay, so we're going to assume that you know the 28 00:03:22.020 --> 00:03:32.820 William Cheng: That this is going to be the case. So therefore, there's always something and the reviews are there one, next one over here would never be no that was sort of going to assume that the current plan is going to be an array. So it's going to be as many current that as their CPUs. 29 00:03:34.230 --> 00:03:39.660 William Cheng: Alright, so let's take a look at the the the issues are the main focus is how to implement a new tax. Yeah. 30 00:03:40.560 --> 00:03:48.750 William Cheng: When they're worthless CPU. The problem with implementing the taxes that you know this code over here, we start this code in the streets that implementation. Right, so, so, so 31 00:03:49.260 --> 00:03:54.480 William Cheng: In that case, what it does is that it tried to see if anything's is locked. If the meetings is not lock. 32 00:03:54.960 --> 00:04:05.700 William Cheng: Okay, so what do we do is that, is anyone said that the matrix like you're the one and there's no other thread that can interfere with it because we're under straight to that. So there's no there's no under CPU. So, therefore, this is our operation. 33 00:04:06.720 --> 00:04:14.580 William Cheng: Okay, but we have multiple CPU, then this situation, we saw the situation already in chapter two, right. We do x plus plus. And then we'll sort of sure that this 34 00:04:15.120 --> 00:04:22.650 William Cheng: Doesn't work because you know the the other CPU can do x plus plus at exactly the same time. And then in that case, you know they're they're going to be in trouble. 35 00:04:23.280 --> 00:04:31.620 William Cheng: So, so if we take a look at the multiple CPU case over here we have CPU and I'm a while Sep number two. What if both CPU are doing exactly the same thing and write out the mutations available. 36 00:04:32.130 --> 00:04:38.130 William Cheng: Then when the meeting is available. That means that new tie some some new times over here. Again, there's a Q inside over here and there's a lock. 37 00:04:38.310 --> 00:04:48.150 William Cheng: And lock equal to zero, me and let me text is available. So both of them is going to, you know, run simultaneously across the bus to examiners location and both of them will see that the meetings is available. 38 00:04:49.320 --> 00:04:55.680 William Cheng: OK. So again, only one CPU will get the bus at a time. Right, so. But if they do it at the same time. What will get a person. The other one, get in that next. 39 00:04:55.920 --> 00:05:01.590 William Cheng: Both of them will see new tax equal to zero. And now, both of them will try to set the new tax law equal to y. So one of them is gonna say 40 00:05:01.860 --> 00:05:08.070 William Cheng: What does that equal to one. And then the next bus psycho. The other CPU also get a set equal to one. So what is the problem with that. 41 00:05:08.520 --> 00:05:11.910 William Cheng: The problem with that is that both threats. Now, things that they have to meet has locked 42 00:05:12.690 --> 00:05:18.000 William Cheng: So therefore you violate the semantics of the new tax. So if you do like this, your implementation on mute has will be incorrect. 43 00:05:18.750 --> 00:05:28.260 William Cheng: Okay, because there will be time we're both will we have more than one to both of you know more than one said they all think that they have to be tax law. So therefore, they're executing critical section code simultaneously. 44 00:05:28.860 --> 00:05:40.440 William Cheng: Okay, so therefore that's not a lot. Right. So the question is, how can we fix this. Alright, so you can think about how to actually fix this pretty soon you're going to come to the realization that there's absolutely no way to implement this in software. 45 00:05:41.790 --> 00:05:48.870 William Cheng: Okay, if you try to implement into software, he's just not going to work. So in the end, if the hardware has to come to the rescue and try to solve this problem. Yeah. 46 00:05:49.230 --> 00:05:59.970 William Cheng: So I'm going to sort of talk about the harvest solution. The solution is that, you know, for every CPU that's out there in order for them to implement a new house like that. They all support it and calming operation. 47 00:06:00.540 --> 00:06:08.130 William Cheng: OK, so the atomic operation. They're different names were one of them is called compare and swap. Right. So compared to see as over here, Kelsey as 48 00:06:09.030 --> 00:06:17.160 William Cheng: OK. So the idea here is that we're gonna go to a memory location over here and we're going to read the memory location, we're going to compare with it if it turns out that there are the same, then we're gonna 49 00:06:17.910 --> 00:06:20.790 William Cheng: We're gonna sort of stopped the content with that memory location with another value. 50 00:06:21.360 --> 00:06:31.140 William Cheng: That so. So this example because you know Castle, we had the first argument. It's an address right it's an integer point over here. So in this case, it will point to the new tax law so that you will know what that means x is locked or not. 51 00:06:31.560 --> 00:06:40.200 William Cheng: Now the second argument over here is, no, it's the old argument and a third argument over here is the new argument. So what you would do over here. I mean, this is kind of weird when we're using C code. 52 00:06:40.470 --> 00:06:49.470 William Cheng: As pseudo code to actually explain how does it compare and swap machine. So it works. Okay, the machines over here is the lowest level. But when he's a high level language to tell you how it works. 53 00:06:49.800 --> 00:06:52.800 William Cheng: Right. So keep in mind that this call is that you implement it on the CPU level. 54 00:06:53.520 --> 00:06:59.490 William Cheng: Yeah, alright. So, what it will do is that it will go to this address and read, you know, read the content of their memory location. So again it lock. 55 00:06:59.820 --> 00:07:08.610 William Cheng: The lock variable can be either zero or one. Okay, so we're going to read them into a temporary variable we here. I mean, if it's inside the CPU, the temporary variable typically is going to be the year 56 00:07:09.420 --> 00:07:19.740 William Cheng: Okay. And then what we do is, I'm going to compare. So we're here with a second argument it very equal, then we're going to go across the bus and right. The, the third argument or we get into that memory location. 57 00:07:20.580 --> 00:07:29.040 William Cheng: Okay, so that's what this is part of compare and swap. I'm going to compare you know what's inside this memory location with the second argument is equal. I'm going to change to the fair argument. 58 00:07:29.670 --> 00:07:39.570 William Cheng: Okay. What if they're not equal if they're not equal. I don't do anything right. If they're not equal over here. I don't I don't say anything. So in that case, if they're not equal only go across the bus to read their memory location and I never model. 59 00:07:41.130 --> 00:07:50.190 William Cheng: Okay, so this one is almost like a function. So in this case, what this operation is I'm going to return the the template variable here, which is the previous value of the lock. 60 00:07:51.570 --> 00:08:02.880 William Cheng: Okay, so, so, so here's the value of a lot can be 01 right so this one is equal to zero, then in this case 10 will be zero. So, we turn to zero. What does that mean, right. So again, I'm going to compare zero guess old if they're the same. They're going to change it to a new 61 00:08:03.930 --> 00:08:11.160 William Cheng: Guy. So in this case, if all equal to zero, then in this case what a return zero. That means that our CPU had changed this one from zero to some other value. 62 00:08:12.120 --> 00:08:22.740 William Cheng: That so so you over here is equal to zero, right, if this function doesn't return zero. That means that our CPU didn't do anything. All we do is look at the variable is it. Oh, it's not equal to, oh, oh. So therefore, we don't do anything. 63 00:08:23.820 --> 00:08:27.930 William Cheng: Alright, so I'll get this is a compare and swap operation. There are some other CPU call it 64 00:08:28.230 --> 00:08:36.780 William Cheng: Read modify. Right, right. And you read it and you modify it and you write it out and they all mean the same thing. What's important to understand is that this instruction. It's an atomic operation. 65 00:08:37.290 --> 00:08:43.560 William Cheng: Okay. And how many operation with respect to what if this is an atomic operation with respect to the entire system. 66 00:08:44.070 --> 00:08:50.340 William Cheng: Okay, so they have what this has done the hallway. So how can guarantee that this one is that is that is that interfere by any other CPU. 67 00:08:51.180 --> 00:08:58.320 William Cheng: Okay, so in the interest of them, you're going to have multiple CPU, I can have 100 CPU when I execute the cast machine structure. This one will be done a comically 68 00:08:58.740 --> 00:09:06.510 William Cheng: Okay, so we automatically read the value of the law, compare against old if they're equal, we're gonna we're gonna change into a new in one atomic operation. 69 00:09:07.410 --> 00:09:14.460 William Cheng: That right so let's take a look at how this is done. So this is done over the bus. Right. So again, the pictures like this web two CPUs over here the lock. 70 00:09:14.730 --> 00:09:20.640 William Cheng: The meeting is over here inside a new types. There's the lock variable over here right could be zero or one that so 71 00:09:20.880 --> 00:09:27.390 William Cheng: So, so what else is on the bus ride on the bus. There's a bunch of signals. There's the address. So we're going to put the address in the new types on the bus. 72 00:09:27.600 --> 00:09:37.590 William Cheng: There's a data that data could be either the, you know, the data is going to be the value of the log when we try to reap on the bus. The large value over here. It's going to go into a CPU when we tried to write, you know, 73 00:09:38.640 --> 00:09:44.730 William Cheng: Data over the bus. Then we're going to write the new value of you here across the bus. Okay. So again, we're gonna pay attention to what's going data. 74 00:09:45.180 --> 00:09:50.100 William Cheng: There's a recent know there's a lot right signals are when they're both zero. Nothing's happening right where you 75 00:09:50.880 --> 00:09:56.130 William Cheng: Are with the release for the one that the CPU is reading for memory wonder y equals one of the CPUs right into memory. 76 00:09:56.730 --> 00:10:04.770 William Cheng: There's also a new signal that we mentioned briefly before and I said we're going to talk about it later on in chapter five. So now we're going to look at the signal called lock. 77 00:10:05.850 --> 00:10:13.800 William Cheng: That. So there's one more thing on the bus over here. There's a lot. We're gonna see how that's being used that. All right. So what we're going to do is that, you know, 78 00:10:14.490 --> 00:10:20.580 William Cheng: Run through a first example we're going to assume that the music is unlocked, which means that the log variable here, equal to zero. 79 00:10:21.240 --> 00:10:29.040 William Cheng: Okay, the operation that we're going to use to grab the new tax okay is cast the address of the law, followed by zero, followed by one 80 00:10:29.490 --> 00:10:36.390 William Cheng: Okay, it's okay if you read the pseudo code, we are what we do, we're going to read the value of the log in the value of luck or equal to zero, we're going to change into a one. 81 00:10:36.870 --> 00:10:43.890 William Cheng: Okay, in this case, he will return the value of zero. So when cast return to zero. We know that my CPU changing from zero to one. 82 00:10:45.150 --> 00:10:52.770 William Cheng: That if it turns out the log value over here is one, right, we're gonna we're going to read the value of the law. We don't get one and will come down to compare against zero, they're not equal. So therefore, we don't do anything. 83 00:10:53.100 --> 00:11:06.840 William Cheng: So in this case, it will return one. So when the cost function over here, return one when we know that, you know, we don't have a lot. Okay so cash return one mean that somebody else has a la kasbah Tony zero that means that we just change it from zero to one. 84 00:11:08.040 --> 00:11:11.940 William Cheng: Alright. So again, it's very important understand that and now we're going to see exactly how this is implemented. Yeah. 85 00:11:13.950 --> 00:11:21.960 William Cheng: So the red arrow over here. Again, it's a IP rabbit. Now this is one machine instructions. So therefore inside the CPU wouldn't start executing the pseudo code inside of CPU over here. 86 00:11:22.170 --> 00:11:30.630 William Cheng: So the first thing that we're going to do is that we're going to go to the edges and the pointer over here will be the address of the log over here. And then we're going to read the value into the execution. 87 00:11:30.900 --> 00:11:31.860 William Cheng: Right. So what does that mean 88 00:11:32.160 --> 00:11:41.010 William Cheng: That means that we're going to start a bus operation. We're going to take the address of the log over here. Again, if you execute code inside the CPU is going to be virtual address. We're going to cover the into a physical address 89 00:11:41.220 --> 00:11:47.400 William Cheng: We're going to put the physical address onto the bus. So we here says on the bus. We're going to see a zero to 831 it's going to contain 90 00:11:47.610 --> 00:11:54.870 William Cheng: And all the assets address a lot, but please understand that this one is the physical address a lot. What this one over here is going to be the virtual address law. 91 00:11:55.290 --> 00:12:03.090 William Cheng: Okay, so we go through accurate translation using the page table over here, convert the ritual is related to the physical act of law and they're going to put onto the bus. 92 00:12:03.930 --> 00:12:09.330 William Cheng: That. And then what we're gonna do is, I'm going to assert the receipt know to say that the CPU wants to read them this address 93 00:12:09.570 --> 00:12:19.770 William Cheng: From memory. So when the memory. See that you know the the real reason over here, equal to one and the address is addressing the memory. Memory will take the content of this memory location and it put it onto the bus. 94 00:12:20.370 --> 00:12:30.390 William Cheng: Okay, so, yeah. So to show you a little delay later then the zero to 31 is going to be the value of the log. And in this case, we assume that the value of the model here is equal to zero because the new tax law. 95 00:12:31.230 --> 00:12:39.660 William Cheng: Okay, so therefore we're going to see a zero. So zero is going to go into the CPU and then zero is going to go into the 10 value over here. Again, this is the yes I just said. 96 00:12:40.260 --> 00:12:45.930 William Cheng: Okay. So this guy's read is equal to one and right equal to zero, that means that means that the CPU is reading from the bars. 97 00:12:46.170 --> 00:12:54.330 William Cheng: What's more important over here is that when we start this operation. This CPU will drive the lock signal onto the bus to lock out the entire bus. 98 00:12:55.320 --> 00:13:03.540 William Cheng: And so the idea of the Roxy, going to the buses that one CPU will be a certain luck on the device while the locks equals zero on the bus. Nobody else gets the bus. 99 00:13:04.980 --> 00:13:12.630 William Cheng: Okay, so your way our CPU basically become the owner of the bar is oh no of the bus and now nobody will get the bus. Okay, so what we'll do is I'm going to 100 00:13:13.080 --> 00:13:24.570 William Cheng: Ask you, the first part of his costume Shashi by reading the value of a look over here into the CPU and during this time we're going to assert a lot. And then when this operation is down, we do not drop them. I'm going to keep the locks it no 101 00:13:25.080 --> 00:13:34.080 William Cheng: Active on the bus. So this way, nobody else will be able to use the bus now. So now we're going to go to the next instructions over here inside of CPU, we're going to compare 102 00:13:34.470 --> 00:13:40.230 William Cheng: Against all right so Tambo be in this example. This is 10 right the zero go to temple of yours will tell me what a zero. 103 00:13:40.440 --> 00:13:50.520 William Cheng: The second argument over here is equal to zero. So zero equal to zero. So what's important happening over here is that there's nothing going on on the bus, other than the signal. The signal is still equals two, one 104 00:13:50.940 --> 00:13:57.810 William Cheng: Okay, you can see that ready to go zero right zero. There's no address. There's no data. There's nothing else going on to the bus, except that look the bus is locked out. 105 00:13:58.410 --> 00:14:05.580 William Cheng: Okay, because our CP over here trying to execute atomic operation. So we'll keep a lock active to block off all the other CPUs. 106 00:14:06.510 --> 00:14:13.680 William Cheng: Then finally, it says a tab will be able to zero and the auto be able to zero, we're gonna say star pointer equals two new again. What a star finder. 107 00:14:13.830 --> 00:14:23.880 William Cheng: Start point over here is going to be the address is going to be the is the locker ball and we're going to save a lot over over here equals two, one so that means that we need to start another bus operation. 108 00:14:24.480 --> 00:14:32.310 William Cheng: So in this case, we're going to convert the virtual address a lot to the physical address in the lock. So in this case, read is going to be going to zero. Right. It's going to be able to one, so they will look like this. 109 00:14:33.090 --> 00:14:43.020 William Cheng: Okay, I'm going to put the physical address of the lock on the bus and then really what a zero right equals to the one so CPU is writing to the bus. So in this case, what did I see you right into the bus. 110 00:14:43.350 --> 00:14:55.200 William Cheng: What over here, new is equal to one, right, and news. The last argument of ego one. So the CPU is writing one two devices over here. We're going to see the data, one being written off the device and now the memory is going to see this addresses address map to the 111 00:14:56.520 --> 00:15:05.100 William Cheng: Map to memory. So what it will do is it'll take this value and then writing to the memory location. So as we're doing this right operation. We're going to modify it, you know, the 112 00:15:05.640 --> 00:15:13.410 William Cheng: Other the other the new tax law value and change it into a one that during all this time the lock signal is still assert it 113 00:15:14.880 --> 00:15:25.620 William Cheng: OK. So again, nobody else gets used of us. Right. So when this is all done. Next thing what we do, we're going to return from temple, we are again this is done inside the CPU and tempo, we're in our example. So equal to zero, right. 114 00:15:25.860 --> 00:15:32.430 William Cheng: At this time, the lock signal will get dropped on the bus and now other CPU. CAN YOU CAN CAN CAN CAN CAN WE CAN USE THE BUS. 115 00:15:33.540 --> 00:15:44.220 William Cheng: Okay, so this is how you implement a system wide atomic operation by using the lock signal to the buzzer. In this case, what are we lacking together on the bus, we're locking these two bus operation on 116 00:15:44.880 --> 00:15:49.560 William Cheng: These two per cycle on the bus. The first one is a recycle and the second one is the right cycle. 117 00:15:49.860 --> 00:16:00.540 William Cheng: Okay, so we're going to read from the boss and I'm going to write a different value into memory location these things is locked together into one atomic operation because during this time nobody else gets to use the memory. 118 00:16:01.590 --> 00:16:06.030 William Cheng: Okay, so nobody else gets to modify the memory. Nobody else gets to read the memory. So, therefore, this is a farming operation. 119 00:16:07.230 --> 00:16:13.530 William Cheng: Right, okay so so again this is a video, we're going to assume the meat has allowed it will look like this. What is the mutations lot 120 00:16:14.460 --> 00:16:25.560 William Cheng: Okay, so, so I just want to emphasize again right if you know if the cast operation return a value of zero. Right. That means that our CPU just did this change the log value from zero to one. 121 00:16:26.430 --> 00:16:30.000 William Cheng: Then the next example over here. We're going to assume that the new tax is actually lock. 122 00:16:30.270 --> 00:16:40.200 William Cheng: It the new taxes, look over here, then the cast operation will fail because when you go to this memory location overhearing going to read a one, and you're going to compare one again Zilla they're not equal, so therefore you don't do anything. 123 00:16:40.680 --> 00:16:44.580 William Cheng: OK. So the picture on the bus is going to look like this right over here. Again, you started out with a 124 00:16:44.730 --> 00:16:54.570 William Cheng: With a physical address of the lock on the bus, you should the recent know and right go to zero. So, in this case, since the new Texas law, you're going to get a one and one is going to get stored inside attempt variable right here. 125 00:16:54.840 --> 00:16:58.350 William Cheng: And then you compare temp tab over here against all odds, equal to zero. 126 00:16:58.620 --> 00:17:10.050 William Cheng: They are not equal. So over here, you're thinking over here you do this comparison over here. So again, the lock signal. It's a certain on the boss. And finally, when you're done over here. You know, you don't execute it right over here. And then you end up dropping the lock right here. 127 00:17:11.430 --> 00:17:17.160 William Cheng: Okay, so you can you can compare these two pictures over here on one looks like this. So, this is when when this function return a one. 128 00:17:17.490 --> 00:17:24.990 William Cheng: That means that you know you didn't get the lock. Somebody else on the lot, and the previous picture over here. It looks like this when they return zero. That means that you on the lock. 129 00:17:26.340 --> 00:17:29.040 William Cheng: Okay, alright. So, this is how it works. 130 00:17:29.430 --> 00:17:40.320 William Cheng: You know, so, so, so this is an atomic operation. So in this case, we're going to lock them you know we unlock the bus upward for for one per cycle and then plus a little bit of time that the CPU actually thinking and turns out that, you know, 131 00:17:40.740 --> 00:17:45.090 William Cheng: That there will be no right operational on the bus over here. And then we need to drop 132 00:17:46.200 --> 00:17:46.560 William Cheng: That 133 00:17:47.970 --> 00:17:54.780 William Cheng: Alright, so that's the cast operation compare and swap it again. There are some other CPU they they use instruction called we modify right 134 00:17:54.960 --> 00:18:05.250 William Cheng: And the same idea. We hear you read a zero you modify the zero to one, and then you buy the one back to the bus. Okay. And if it turns out when you read equal to one day in this guy. You don't modify it and you just dropped a lot 135 00:18:06.090 --> 00:18:08.550 William Cheng: Okay, so they all amounts would be the same thing. Okay. 136 00:18:09.420 --> 00:18:16.260 William Cheng: All right, so we can use the cast operation to implement a different kinds of lots and it's got a lot of noise and it's called spin lock. 137 00:18:16.650 --> 00:18:21.300 William Cheng: Right. So again, the meat AX represented as a bit of 00 meaning that the new tax do that. 138 00:18:21.720 --> 00:18:29.520 William Cheng: So, so I guess I shouldn't say New types will be, as you said, the spin lock okay zero, meaning that the spin lock and unlock and one is the spin out of LA. 139 00:18:30.000 --> 00:18:34.530 William Cheng: Oh, yes. Oh, yes, spin lock new tag. They're all. They all mean the same thing, right, just slightly different contacts. 140 00:18:35.160 --> 00:18:39.870 William Cheng: So we can implement a smear rockin this way. So what is functioning customer. Okay. So this guy's 141 00:18:40.500 --> 00:18:43.770 William Cheng: Again lock is just the new tax if we want the lock them up. That's what do we do 142 00:18:44.130 --> 00:18:52.050 William Cheng: Okay, we're gonna put the calculation over here in an infinite loop. If we don't get the new title. Want to keep trying, trying to enjoy until eventually we get the new tax. 143 00:18:52.590 --> 00:18:57.870 William Cheng: Okay, well, we'll get to spend on that. So when this function returns the one, then we know that we don't 144 00:18:58.530 --> 00:19:01.170 William Cheng: We know that we don't have a lot. So therefore, we're gonna stay in the interim 145 00:19:01.590 --> 00:19:05.250 William Cheng: While this function keep returning one, that means that somebody else on the new tax. 146 00:19:05.520 --> 00:19:18.420 William Cheng: Somebody else on the spinner. We're going to keep staying inside the signal. But as soon as this function returns zero, what does that mean that means that my CPU is just changing from zero to one. So in this case, I'm going to return by Spin out, and now I'm the owner of the spin off. 147 00:19:20.400 --> 00:19:25.080 William Cheng: OK. So again, you know, this is. Yeah. So, by, by the way, the textbook starting to make mistake over here. So again, 148 00:19:25.800 --> 00:19:31.980 William Cheng: This is that the correct way I think technology has an exclamation mark line in front of it and that's that's wrong. Yeah. All right. 149 00:19:32.490 --> 00:19:38.520 William Cheng: How do I love. It's been not right. So again, I'm going to assume that your code doesn't have any bugs you only call spend on luck. When you own this be law. 150 00:19:38.670 --> 00:19:45.330 William Cheng: So in this case, the log variable has to be one, right, because you're the one that changes zero to one. So, therefore, only you can change it back on 120 151 00:19:45.720 --> 00:19:51.060 William Cheng: Okay, so therefore, how do you change it back on one to zero. So, over here, in this case, what we're gonna do is, I'm going to simply send it back to zero. 152 00:19:51.390 --> 00:19:58.500 William Cheng: Okay, we don't need a cast operation because we know that we own the spend lots and it's been like value must be equal to one and we're simply going to change it to a zero. 153 00:19:59.190 --> 00:20:02.970 William Cheng: Okay. So in this case, there's no requirement to use the cast operation that 154 00:20:03.900 --> 00:20:11.610 William Cheng: Right. So, by the way, this is called the non Eve spin off because this one is actually really, really bad. Okay, so if you implement your car like this. What does the bus gonna look like. 155 00:20:12.210 --> 00:20:22.050 William Cheng: Okay, so remember the example that we use over here is that you your thread doesn't own the spin lock so that means that somebody else on the spin off. So in this case, every time when they executed cast machine structure in 156 00:20:22.440 --> 00:20:33.030 William Cheng: Which one is going to look like this is gonna like this one, or it's going to look at the other one, right. This example here is for the case that we actually grabbed a lot. So this picture will look like it's going to be what it looks like. Well, we didn't 157 00:20:35.070 --> 00:20:44.340 William Cheng: We didn't grab a lot with somebody else on the law now. So if we start executing code like this, what is the bus gonna look like. Okay, so let me clean up this clutter, a little bit over here, right. 158 00:20:45.630 --> 00:20:54.510 William Cheng: Now, so what happened is that, you know, our CPU is going to do this bus operation. And then we print those out that the lock value equal to one. So, therefore, we're gonna try again immediately. 159 00:20:55.020 --> 00:21:00.390 William Cheng: Right. Because over here we're putting inside of infinite loop over here. So we're going to do this over and over again. So you can see the signal the 160 00:21:00.780 --> 00:21:05.550 William Cheng: Signal under the bus is going to be lock is going to be assertive. During this time, and then as soon as we're done, we're going to 161 00:21:06.030 --> 00:21:11.790 William Cheng: Circle lock signal again like this and then as soon as we don't want to organize several oxy know again sort of lost him again. 162 00:21:12.570 --> 00:21:23.280 William Cheng: Okay, so this case the lock signal will be assertive, most of the time until the other thread give up the synagogue and the other their own the spin up for a very long time now. Now that you know the locksmith on the bus go look like this. 163 00:21:23.820 --> 00:21:29.400 William Cheng: Okay, this is really, really bad because when the log signal. It's a signal to the bus. Nobody else gets the bus. 164 00:21:30.390 --> 00:21:40.050 William Cheng: Okay, so for example, if your network interface card just, you know, just got something a lot a lot of data from across the internet and now it needs to do DMA operation to copy the data on the network interface card in the memory. 165 00:21:40.470 --> 00:21:50.220 William Cheng: Then, when can they transfer data. Okay. In that case, the network interface card can only transfer data, maybe for bite at a time doing the time this the lock over here is not assertive. 166 00:21:51.300 --> 00:21:56.670 William Cheng: Okay. So, therefore, you know, when you tried to transfer a lot of data on and then one interface card to memory will take a very, very long time. 167 00:21:57.090 --> 00:22:04.860 William Cheng: And also we just tried to transfer data into memory. We're gonna have exactly the same babo so when you assert the lock signal for, you know, for very, very long time. Yes. 168 00:22:05.610 --> 00:22:09.960 William Cheng: Sir, good luck. See, but very often onto the bus, you're going to destroy the entire system performance. 169 00:22:10.680 --> 00:22:15.750 William Cheng: Okay, because all your devices when they tried to transfer data into memory. Memory, they all going to take forever. 170 00:22:16.680 --> 00:22:22.290 William Cheng: Okay, so therefore you should never implement your spin lock this way. This is a really bad idea that 171 00:22:23.070 --> 00:22:33.540 William Cheng: All right, so listen to do right so here's the better spin up. OK. So I'm going is that you know the problem over here is that you, beloved, variable is equal to one, that you should not execute a cash machine structure. 172 00:22:34.890 --> 00:22:44.490 William Cheng: Okay, so let me say it again if cat, you know, if the log value over here you go to one. Well, that means that somebody owns it. So, therefore, I should not use cost because because if I use cuz I will be very nasty to the system. 173 00:22:45.300 --> 00:22:50.310 William Cheng: Okay, so therefore the only time I'm allowed to use cause is when the meetings value equal to zero. 174 00:22:51.210 --> 00:22:57.660 William Cheng: Okay, so here's a better spin log over here. Again, I'm going to stay inside the interval here because I need to keep trying. Right. I won't give up until I get 175 00:22:58.320 --> 00:23:05.310 William Cheng: I get a lot. So therefore, the person we're going to do is I'm going to check if the meters is equal to zero. Now, that if the meat x is equal to zero. 176 00:23:06.000 --> 00:23:14.970 William Cheng: So if it is it is it is not equal to zero. What do we do, we're going to come back to the integral over here. Then we're going to read at the music signal that do not value again. 177 00:23:15.420 --> 00:23:24.060 William Cheng: Right. So the example that we saw over here, the new technology is equal to one. So in this case, this test will fail. So what happened is that we're going to keep reading the value because we're going to keep getting one forever. 178 00:23:24.360 --> 00:23:31.530 William Cheng: But we are not asserting the lock signal to the bus because over here, we just simply go to go across the bus to read the value of the mute hacks. 179 00:23:32.520 --> 00:23:44.310 William Cheng: Okay, so we're being very, very nice to the bus. So when we see the music's not equal to what that means that meet our data is available, then we tried to grab the meat is when you try to grab the new tax you have to use the cost of operation because of where multiple CPU. 180 00:23:44.940 --> 00:23:52.860 William Cheng: Okay, so therefore, as soon as you see the Medellin go to zero. You can then use the CAS operation so it can return to zero, that means that now you 181 00:23:53.070 --> 00:24:00.630 William Cheng: You're the CPU that changed from zero to one. So you just gotta, you gotta break out of the infinite loop and then you return on spin off and now you're still will be the one that on the spin off. 182 00:24:01.410 --> 00:24:05.280 William Cheng: And then if it turns out the cast operation over your return to him to evaluate what 183 00:24:05.490 --> 00:24:13.260 William Cheng: That means that you are lucky. Somebody else grabbed the meetings right before you wasn't this guy to get you go back and loop over and over, over again without shutting the locks and no 184 00:24:13.920 --> 00:24:22.320 William Cheng: Okay, so if you do it this way on the bus. What is the last in the last segment is going to be assertive only once in a while. Yeah. And then, you know, 185 00:24:23.100 --> 00:24:26.400 William Cheng: After somebody reads the new tax. Again, you gotta serve not only for very short period of time. 186 00:24:26.790 --> 00:24:37.650 William Cheng: Okay, so this way you know if you know what interface car or get this controller need to charge a lot of data they can actually go very, very quickly are doing to find the lock signal is not sure. Okay. And that's exactly what you want. Yeah. 187 00:24:39.300 --> 00:24:49.500 William Cheng: Alright, so this is go spin up spin up is also, it's too busy waiting right so it's very, very wasteful guys we mentioned before in chapter two that will you try to wait for something you shouldn't have the CPU. 188 00:24:50.460 --> 00:24:58.170 William Cheng: Okay, so even though this works. Okay, so, especially if he is nice. Now you've spent out and it's been a long standing in the same way. So in that case, this 189 00:24:58.470 --> 00:25:09.090 William Cheng: It worse. But it's very, very wasteful, you know, because, because you're gonna keep eating out the CPU cycle, you're going to drain the battery. So therefore, the right way to wait for something right is to, you know, go to sleep. 190 00:25:10.560 --> 00:25:20.610 William Cheng: Okay, so let's try to see if we can actually make the spin lock change it into us as you change into a blocking log. So this case we're going to wait for it. And then we're gonna we're gonna wait for it by going to sleep. 191 00:25:21.690 --> 00:25:32.250 William Cheng: Okay, so again, which we still assume that we have multiple CPU that I don't know. You know, our contacts we have multiple CPU. So let's see, we can we can change the spin lock into a parking lot. Okay. 192 00:25:33.390 --> 00:25:38.700 William Cheng: Alright, so the call here. This code is very, very similar to the street and implementation of the new tax. 193 00:25:39.000 --> 00:25:45.090 William Cheng: Okay. So actually, it's exactly the same except you know the only difference over here is that instead of checking whether the new tax law. 194 00:25:45.330 --> 00:25:52.680 William Cheng: If a threat is holding the new tax, we're going to actually remember the holder of the new tax. So the new tax code or equal to know what that means that the new tax is available. 195 00:25:52.980 --> 00:25:56.490 William Cheng: Okay, if the meat that's holder is not equal to know that means that somebody else actually own the meatheads 196 00:25:56.700 --> 00:26:00.600 William Cheng: Okay. Otherwise, you can actually contract this code with the other code. They look exactly the same. 197 00:26:00.840 --> 00:26:10.890 William Cheng: Okay, so this while we're also going to change the name. This one's called blocking log. And again, new tech has two things. One is the mute high school and the other one is that which thread on the new tax law right 198 00:26:11.910 --> 00:26:23.730 William Cheng: So, I mean, you know, we mentioned before, the you know the the new tax law chronometer code that we saw before, only work under the sheets or any implementation. So we already know that this code is not going to work when there's multiple CPU. 199 00:26:24.780 --> 00:26:30.270 William Cheng: Okay, so, so, so, so why this wouldn't work. Right. So one example over here is that you have, you have to threats. 200 00:26:30.540 --> 00:26:35.760 William Cheng: Executing blocking rocket exactly the same time if the mutants holder over here you go to do to know 201 00:26:36.000 --> 00:26:45.600 William Cheng: Both of them will think that you know that the music is available and then both of them will be that they actually they will execute this day, man. And now the month or the new tax holder is going to be 202 00:26:47.640 --> 00:26:53.640 William Cheng: Going over the race condition right whoever who execute this instruction. Second is going to be. It's going to be the mute. I told her. 203 00:26:54.000 --> 00:27:00.150 William Cheng: Okay. What's worse is that both you know threads going to return from blocking out over here, and both of them would think that they own the new tax. 204 00:27:01.080 --> 00:27:06.900 William Cheng: OK. So again, this is the problem that we start with right so now if we change it to broaden our going to end up with exactly the same situation that 205 00:27:07.410 --> 00:27:12.390 William Cheng: The other possibility over here is that, again, you know, we have one side running up here. The third one is actually the call. We hear 206 00:27:12.690 --> 00:27:18.270 William Cheng: That too is actually doing over here. So threat to is the owner of the mute it elsewhere to try to release the new tax. 207 00:27:19.140 --> 00:27:25.710 William Cheng: Okay, well, Phil was over here, executing the call simultaneously in a different CPU. So, so I will see that the new to holder or is not equal to know 208 00:27:26.100 --> 00:27:30.870 William Cheng: Right because threat to actually own the new time slot to at the same time over here. I'll try to unlock me test. 209 00:27:31.050 --> 00:27:37.800 William Cheng: So what do you do, is that it will look at the queue to see them. You talk to you is empty or not at this time the mute IQ is empty. So what happened is that you 210 00:27:37.980 --> 00:27:45.780 William Cheng: Were to over here, it will actually said to me that order important now what at the same time in the first CPU, it will see that the mutants holder over here is equal to know 211 00:27:46.500 --> 00:27:57.120 William Cheng: So maybe that's what we hope is not good enough because equal to select you. So what you would do that, it will add itself to the ad itself to the new tax queue. And then what it does and it will cost less switch to give up the CPU. 212 00:27:57.960 --> 00:27:59.310 William Cheng: Okay, so what's wrong with this code over here. 213 00:28:00.120 --> 00:28:12.660 William Cheng: Well, so if both these two things happened simultaneously in two different, two different CPU through our two over here. It's going to, you know, set the new that total equal to zero. So why is going to fall asleep in the meantime skew and nobody's going to wake up to that one. 214 00:28:14.010 --> 00:28:22.950 William Cheng: Okay. So in this case, you have two different CPU, they're executing simultaneously. So in this case, due to this race, the race condition. So, one can end up sleeping to meet has to be here forever. 215 00:28:23.820 --> 00:28:30.210 William Cheng: Okay. So in this case, again, this call is not supposed to work other than on the street that assumption is that clearly we have multiple CPU. 216 00:28:30.720 --> 00:28:32.820 William Cheng: The code doesn't work. And that's what's gonna be the solution. 217 00:28:33.690 --> 00:28:39.060 William Cheng: Yeah, so the solution over here is that, you know, this code and this code over here. They need to be mutually exclusive. 218 00:28:39.420 --> 00:28:50.520 William Cheng: Right, also in the previous example, we have this line of code over here to threats can be executing code and same time. So what we need to do is that we need to make the blocking lock and the blocking off function over here, we need to make them. 219 00:28:50.880 --> 00:29:00.870 William Cheng: You know, the critical section code. Okay. So this guy is critical session cool with respect to what. Well, we're gonna do that you know as soon as we have learned about spin law and we'll use multiple CPU, we can actually 220 00:29:01.410 --> 00:29:02.880 William Cheng: We can actually use a spin off right here. 221 00:29:03.390 --> 00:29:15.990 William Cheng: That. So therefore, in this case, what we can do right here. Yeah, so, so, so, so, so this code and this call. We want to make sure that they are mutually exclusive. We can do spin lock like you and spin on lab right here. And then the 222 00:29:16.260 --> 00:29:25.230 William Cheng: For the other function. We can also to spin, spin on lock over here. Once we do that, this code in this code, they will be mutually exclusive with respect to the spin lock. 223 00:29:26.550 --> 00:29:28.230 William Cheng: Then, so therefore you will look like this. 224 00:29:28.740 --> 00:29:40.890 William Cheng: So here I'm going to add this life Spurlock right spin on lock spill out will be USP also again this luck. Good luck inside of you that there are different lots. Right now we're gonna do to lots. We're going to use a lot to implement a blocking law. 225 00:29:42.390 --> 00:29:43.470 William Cheng: Okay, so in this case. 226 00:29:44.490 --> 00:29:58.200 William Cheng: Since we're calling spin out what we're, what we're being very wasteful, we're gonna we're gonna end up wasting the CPU over here. But as it turns out, this code actually has a bigger problem that this this code, why should deadlock because over here, we actually would cost less which 227 00:29:59.340 --> 00:30:08.550 William Cheng: Law. So let's say that the first one over here customers over here and then the fans are that the new tax is not available, right. So, therefore, what do we do say added something to run queue and now it's going to cost less which 228 00:30:08.820 --> 00:30:11.070 William Cheng: When it costs less, which is a screen, lock, lock or not. 229 00:30:11.670 --> 00:30:17.820 William Cheng: What it's been like is locked right so therefore the second to read over here, when they tried to allow me to ask what then again. The second thing is gonna get blocked wherever 230 00:30:18.300 --> 00:30:26.160 William Cheng: OK. So, again, in this case, we're going to end up with with it with a deadlock, you know, because you know the first read over here will fall asleep with the spin lock, lock. 231 00:30:26.850 --> 00:30:33.780 William Cheng: Okay. So, therefore, what is the solution. Well, the solution, maybe right before fall asleep. Over here, we need to add a spin on law and so in this case we need to add 232 00:30:34.380 --> 00:30:45.360 William Cheng: We need to actually move the spin off over here to be right before this work and also in the case where the other the new tax holder equals know we still need to spend our lives. So we need to add the summit or move the system. Now over here as well. 233 00:30:45.870 --> 00:30:48.930 William Cheng: Okay, so when we do that, is that we're going to end up looking like this. Right. 234 00:30:49.230 --> 00:30:55.620 William Cheng: Because spin off right here. Now, there are two different places on the spin on lot what is right here at before the switch, because we don't want to 235 00:30:55.860 --> 00:31:04.260 William Cheng: Mess with with the spin lock, lock, and then in the case when the meat. That's all there is to know. We also need to spin off right here that this call also doesn't work. 236 00:31:05.670 --> 00:31:12.240 William Cheng: Okay, why doesn't work so. So as it turns out, this code doesn't work because there's a race condition and this race condition I should be pretty tricky. 237 00:31:12.600 --> 00:31:22.230 William Cheng: Okay, so let's take a look at this special case with this code doesn't work there. So we're going to have, you know, two fed running once they are still one is actually running over here and set you over here is unlocking 238 00:31:22.680 --> 00:31:31.470 William Cheng: I want you to meetings over here that. So, therefore, Robin. Is that so one. Again, this is the same example that we saw before. I feel one called you know the 239 00:31:32.310 --> 00:31:40.830 William Cheng: CEO and CO, CO, CO, CO parking lot over here. And then what do we do, is that he will acquire the spin out to make sure that this code and this over here are mutually exclusive. 240 00:31:41.130 --> 00:31:50.820 William Cheng: Okay, so, so right now see the mutants holder is to choose are good for Phil, I'm going to add itself to the to the meat AX you and then in order for it costs less which it's gonna it's gonna cost me an arm. Ah. 241 00:31:51.510 --> 00:32:01.980 William Cheng: OK, so now. So one is no longer only the spin out and now threat. You had to overcome was actually waiting for the spin lock and now he was gonna come in and it is possible threat to execute much faster than that one. 242 00:32:03.150 --> 00:32:11.370 William Cheng: Okay, why is that right, because the CPUs mid may be different. One of the CPU might be more powerful than the other one. And also inside the CPU. There's all kinds of patches. 243 00:32:12.030 --> 00:32:17.670 William Cheng: So when you have cash. Isn't that a CPU, you know, once you can actually run faster than the other one. Okay. So yeah, if you don't know what 244 00:32:17.940 --> 00:32:22.410 William Cheng: For W people you know what the, you know, caches and data CPR. So if you don't know what they are that the 245 00:32:22.680 --> 00:32:30.600 William Cheng: That's okay. Okay, so we're just going to assume that the CPU can run a different speed if for some reason. The second CPU is very, very fast. As soon as you unlock 246 00:32:30.930 --> 00:32:39.390 William Cheng: The spin out in the first CPU. The second one is going to return a spin off over here and going to start executing code right here. So, what it will do is that it would look at to see if the queue is empty. 247 00:32:39.660 --> 00:32:45.630 William Cheng: It's empty. Well, actually, you know, three number one over here is actually sleeping inside of me attacks you, so therefore this is the 248 00:32:46.230 --> 00:32:58.860 William Cheng: This is actually not gonna be empty. So what do you would do is that they will remove one from the new tax you over here. So on to the lunch you that. And now, so that she was gonna it's gonna cost spin on a lot and he was going to return palms up blocking a lot 249 00:32:59.880 --> 00:33:06.300 William Cheng: OK, so now so often is that third one over here is inside. What is that she was over here also give up the CPU right away. 250 00:33:07.170 --> 00:33:13.110 William Cheng: And so the assumption over here is that under these really, really, we're race condition. The second CPU is super fast. 251 00:33:13.350 --> 00:33:21.750 William Cheng: Threat to over here is actually going to give up the CPU or to give us the CPU is going to give us a CPU to throw one. So, therefore, this time. So one is running in both CPUs. 252 00:33:23.850 --> 00:33:31.620 William Cheng: OK, so the first case for one over his new calling fest which well you know the so on also getting DQ I'm putting out a run through and start running out of CPU. 253 00:33:31.980 --> 00:33:35.040 William Cheng: Are you allowed to have once I run into CPU simultaneously. 254 00:33:35.520 --> 00:33:40.260 William Cheng: I mean clearly that's not a lot right biggest threat is an abstraction and CPU is available, you can I have the same thread. 255 00:33:40.500 --> 00:33:50.760 William Cheng: Running into Devon CPU as okay even though this is very unlikely to happen. But if you have different speed of your CPU this case can happen. So, therefore, this is really not about that. 256 00:33:51.690 --> 00:34:02.220 William Cheng: Alright, so let's get into the solution. Oh, here's the acid real question here. So maybe the problem here is that we need to pass the spirit over here in southwest, which maybe somewhere inside threats worse. That's what we should unlock 257 00:34:02.550 --> 00:34:11.340 William Cheng: A harvest in LA. Okay. But in that case is kind of weird, right, because the threat switch over here, we're simply give up giving up the CPU. So if it takes an argument with a spin lock that looks kind of weird. 258 00:34:11.700 --> 00:34:15.210 William Cheng: Okay. So at this point I'm going to surrender. We're going to say there's no solution for that. 259 00:34:16.860 --> 00:34:22.920 William Cheng: Okay, so, so for multiple CPU. If you want to implement blocking lot at this point we have no solution. 260 00:34:23.880 --> 00:34:27.540 William Cheng: Or I'm going to give up and they don't going to see what kind of solution will get that we can actually end up 261 00:34:28.140 --> 00:34:37.290 William Cheng: And my hobby. If you only have, you know, multiple CPU over here and you try to do you tried to a sleeping lot. As it turns out that there's really no way to do that. 262 00:34:38.070 --> 00:34:47.970 William Cheng: Alright, the next thing we're going to look at is called few tags are we mentioned before in Linux to implement few tag a few tax debts blah fast user mode. So sorry fast user space new tax. 263 00:34:48.420 --> 00:34:54.690 William Cheng: Okay, so this is the users. So again you Linux, we are implementing one by one model so certain companies are the kernel. 264 00:34:54.870 --> 00:35:02.010 William Cheng: Of a we showed a lot of new tax. We need to check with the meetings available user space. If it's available, we're going to grab the new tax welcome inside the cardinal 265 00:35:02.430 --> 00:35:09.780 William Cheng: OK, so now we know how to grab the mute button user space, right. Okay, we're going to use the cast machine structure to grab the new tax in the user space. 266 00:35:10.050 --> 00:35:13.710 William Cheng: Or as a please understand that the cast machine instruction is not a privilege instruction. 267 00:35:14.160 --> 00:35:17.730 William Cheng: So, therefore, you can actually use cast in the user space, right, so we're gonna see how do you actually do that. 268 00:35:17.910 --> 00:35:23.430 William Cheng: That if it turns out the new Texas not available in this case, what do you have to do. Well, you have the companies that have Colonel because you have to wait. 269 00:35:23.640 --> 00:35:31.830 William Cheng: You're fast to go to sleep. Go to sleep. The only way you can go. You can go to sleep in a one by one motto since thread to implement that kernel is that you have to make a system called 270 00:35:32.310 --> 00:35:39.390 William Cheng: That. So we're going to assume that there are these two system call we hear that are available to you. Number one is called few texts way if you have to wait for a few tasks. 271 00:35:39.570 --> 00:35:45.240 William Cheng: You have to come to sleep inside of her and also this guy's gonna call few times way. So this one is going to be a system called gonna end up inside carnal. 272 00:35:45.660 --> 00:35:48.270 William Cheng: Yeah, there's another system called a few tax wake 273 00:35:49.080 --> 00:35:52.560 William Cheng: That. So when you need to wake up another thread. So let's say that you are unlocking 274 00:35:52.830 --> 00:36:00.840 William Cheng: A long commute is where you're pretty shocking to me that you need to wake up a thread that's waiting for that waiting for them it is. So how you wake up another threat. 275 00:36:01.200 --> 00:36:05.340 William Cheng: Well, again, since implement inside of Colonel, there's no way for you to wake up another 276 00:36:05.670 --> 00:36:09.660 William Cheng: user space because the threats are sleeping inside the Colonel, right. So, therefore, in this case. 277 00:36:09.870 --> 00:36:16.320 William Cheng: We need to provide another system called call few texts way, this way, this isn't how are you going to go inside a kernel and wake up the other thread. Yeah. 278 00:36:16.530 --> 00:36:21.060 William Cheng: How do you wake up. The other thing that you pick up that slip on the meat IQ and you move it into the monkey. 279 00:36:21.570 --> 00:36:35.100 William Cheng: Okay. So yeah, this function over here is a non blocking call the always return right away. Well, few times where it over here. It's possible that you end up sleeping. Is that apparently so we're going to assume that they are these two system calls to support a few times operation that 280 00:36:36.690 --> 00:36:46.410 William Cheng: We also sort of assume that there's also going to be some other atomic operation. One of them is going to be the atomic increment operation. The otherwise called the atomic detriment operation. 281 00:36:46.680 --> 00:36:50.910 William Cheng: So again, in this comma increment over here, we're gonna do, you know, we're going to be up 282 00:36:51.690 --> 00:37:02.010 William Cheng: To the new tax law value plus plus. So if you want to go from zero to a wise or this case or you need to increment it. So the way we do this is that this operation over here. It's going to be atomic 283 00:37:02.700 --> 00:37:10.530 William Cheng: Okay, so how do we implement this, and how many operation. Well, as it turns out, Intel is actually a very simple Intel for every, you know, for, for, for a bunch of machines structure in 284 00:37:10.740 --> 00:37:15.870 William Cheng: Every machine stretching and so for example we starting starting over here says move something followed by moves up or something like that. 285 00:37:16.200 --> 00:37:19.800 William Cheng: Every machine shops will can actually add the word lock in front of it. Okay. 286 00:37:19.980 --> 00:37:29.760 William Cheng: Well, we add the word lock in front of it right before you execute this instruction. We're going to assert the loxodonta the bus and then if the next instructors also law we not going to release the lock seat on the bus. Okay. 287 00:37:29.940 --> 00:37:35.490 William Cheng: Only when we finished all the law construction in India. We're going to unlock we're going to remove the locks on the bus. 288 00:37:36.300 --> 00:37:43.530 William Cheng: Because of what you guys actually very, very simple to implement, you know, atomic operation. Okay, farming operation using assembly code that 289 00:37:44.130 --> 00:37:51.210 William Cheng: So that, you know, this depends on asserting the locks exalted above right so India was still depends on hardware in order for this to work now. 290 00:37:51.570 --> 00:37:58.620 William Cheng: Alright, so you can actually do a calming incremental via and this function also returns because my sis as return star Val plus plus. 291 00:37:59.160 --> 00:38:06.180 William Cheng: OK, so the plus plus over here. It's going to be done after you return the value over here. So again, this function will return the previous value of the lock. 292 00:38:07.020 --> 00:38:18.570 William Cheng: Okay. The. Similarly, the other one, the atomic document operation. Again, you're gonna you're gonna return value first and then you're going to decorate the values are. And this will also deck, we're gonna we're also going to return the previous value of 293 00:38:19.290 --> 00:38:25.080 William Cheng: Of a lot bearable, guys. Again, this is consistent with the cast operation right when you put one the cast operation. 294 00:38:25.290 --> 00:38:35.520 William Cheng: The first argument against going to be the value of the new tax and then when the function returns the always return the previous value at that address. Okay, so all these three functions over here always return the previous value. 295 00:38:37.440 --> 00:38:43.320 William Cheng: Right, so, so, so over here. So, so if you call a common document. What does it mean when He returns a one. 296 00:38:44.340 --> 00:38:54.030 William Cheng: Well, when he returns the one that means that you have just changed it for one to zero right when you call the atomic increment. What is the return zero. Let me say you have just changed it from zero to 190 always return the previous yeah 297 00:38:55.110 --> 00:39:02.370 William Cheng: Alright, so let's take a look at the implementation over here the textbook. It is showing you something. They are some encouraging women Asian over here. We're going to skip that. 298 00:39:02.640 --> 00:39:08.040 William Cheng: And we're going to go directly into the solution. OK. So again, the textbook over here is wrong. We need to write it like this. 299 00:39:08.730 --> 00:39:15.270 William Cheng: So let me explain this code to you guys so so okay so this code is the actual implementation of a few tasks. 300 00:39:15.780 --> 00:39:24.690 William Cheng: Okay, you can see there's only a few lines of code. So again, it's very, very tricky code. Okay, so, so in this case the few times now the ledger can be zero or one. You can also be too. 301 00:39:25.860 --> 00:39:31.500 William Cheng: Okay, so this is again zero means the same thing. Zero means that the few taxes online. So I'm going to use the word few tax. 302 00:39:31.740 --> 00:39:40.980 William Cheng: Tax interchangeably, because they all report to the same thing that says zero, meaning that the few tax or the new tax law one or two, meaning that the few times in the new tax law. 303 00:39:42.060 --> 00:39:47.640 William Cheng: Okay, so. So what's it doing to do one or two. Right. So one means that the you know the you know the few Texas log 304 00:39:48.270 --> 00:39:54.900 William Cheng: You know, but but we know that there's no waiting for that. So what does that mean there's no waiting said there's no waiting threat inside the colonel because 305 00:39:55.350 --> 00:39:57.420 William Cheng: In order for us to wait for you need to go into the kernel. 306 00:39:58.050 --> 00:40:06.240 William Cheng: Okay, so this is kind of weird over here, right. So we know that you know the few text is locked, but we somehow we know for sure that there's nobody. Wait, he's out of kernel that 307 00:40:06.780 --> 00:40:13.230 William Cheng: The, the future value is equal to two. Again, that means that the few times is locked by somebody with a possibility or weightings let's 308 00:40:14.010 --> 00:40:21.750 William Cheng: That's what this one is saying over here that we don't really know what's going on inside the current. Oh, why would the values go to to over here. Maybe somebody waiting for the colonel maybe somebody that equation as 309 00:40:22.410 --> 00:40:26.190 William Cheng: Well, we don't really know. Because in order for us to know we have to go inside the Colonel. 310 00:40:27.270 --> 00:40:33.000 William Cheng: Okay, so therefore, when you see the value of two. You're really not sure. All you know is that a few times as long. But I don't know if somebody went inside. 311 00:40:34.770 --> 00:40:44.250 William Cheng: Then alright so let's take another the employees over here. So again, the few times that it can be 01 or two right zero, meaning that a few times available one or two of these are their law. Yeah. 312 00:40:44.850 --> 00:40:52.440 William Cheng: So here's the new tax law corporation over yet. Right. So again, the few times over here has a Q AMP lab value as a few times value can be equal to 01 or two. 313 00:40:52.740 --> 00:40:59.940 William Cheng: That. So we're going to do is, I will use the class operation over here to try to grab a few times over here. So again, if this one, she returned zero, what does that mean 314 00:41:00.300 --> 00:41:06.030 William Cheng: That means that we are the thread that changing from zero to one ratio. In this case, if this one, she returned a zero over here. 315 00:41:06.570 --> 00:41:16.020 William Cheng: The code over here says ESC pursue the return value because if it's not equal zero. Then we're going to listen to this call is equal to zero, then we're going to return from the lock operation and now on the few times. 316 00:41:17.460 --> 00:41:26.100 William Cheng: Okay. So does that make sense. Right. So again, if, if my thread is a thread that trend Obama zero to one, I'm going to return on luck over here and not all die on the few tax. 317 00:41:26.700 --> 00:41:38.790 William Cheng: Okay, so therefore this implementation satisfy that requirement of the one by one model for Peter meatheads lot because even, you know, if the mutates available user space we're going to grab the new tax without making a system called 318 00:41:40.440 --> 00:41:46.050 William Cheng: Okay, so even the taxes available over here. We're gonna change to a world where every Tony immediately do we make any system called No, we didn't make any sense. 319 00:41:46.590 --> 00:41:52.320 William Cheng: So therefore, this satisfy that requirement for the one level model. Okay, to implement it to the implementing the attacks. 320 00:41:53.070 --> 00:41:59.940 William Cheng: Well alright so the enterprise is the one that's more complicated, right. So what if this one doesn't return zero, then essentially which are one or two. 321 00:42:00.510 --> 00:42:05.040 William Cheng: Okay. So in this case, see over here will equal to one or two if you're going to the internet move over here. 322 00:42:05.460 --> 00:42:11.340 William Cheng: Okay, so yeah, one or two, meaning that somebody else on the few times, but we don't really know if somebody ratings that a kernel or not. 323 00:42:11.550 --> 00:42:19.200 William Cheng: That. So therefore, we hear what we do is that the first thing that we do that, we're gonna say if C equals to chew if he was doing that. Maybe somebody is actually see things that are Colonel 324 00:42:19.410 --> 00:42:33.300 William Cheng: So in this case, since I didn't grab the few times I need to go sleep behind those threads that may be inserted, Colonel. Okay. So, therefore, if c equals to to what I have to do is I have to call few times where I need to go into the kernel immediately and get behind other threats. 325 00:42:34.320 --> 00:42:42.990 William Cheng: So therefore, this guy's if you go to, I simply computex way. And now my throat will go to sleep. Okay. What I've seen is not going to lie. So God sees not equal to zero. 326 00:42:43.830 --> 00:42:49.770 William Cheng: Sees not equal to two. So they will see has to be equal to one, right. So see those two one, meaning that you know 327 00:42:50.340 --> 00:42:54.840 William Cheng: We'll see was one meaning that the few Texas law, but nobody's waiting inside the Colonel. 328 00:42:55.590 --> 00:42:57.810 William Cheng: Okay. So, therefore, what should I do what I need to go into 329 00:42:58.140 --> 00:43:09.480 William Cheng: I need to go to sleep inside corner right because over here. I don't have a few tasks. So in this case I need to go into the other. I need to go into the other the other the Colonel. So therefore, one will be the incorrect valuable for you guys. I need to change it to a to 330 00:43:10.500 --> 00:43:18.630 William Cheng: Have so therefore, in this case for C equals two, one, I'm going to execute this I'm gonna take cast one to two. So if this function return one. What does that mean, 331 00:43:18.780 --> 00:43:30.840 William Cheng: That means that I changed it from a one to choose. In this case, you know I successful genuine one to two. So, therefore, I need to copy tax way and goes to sleep inside of Cardinal. Okay, so when they return the value of one. I then the next thing I will do is that 332 00:43:31.860 --> 00:43:35.700 William Cheng: It is that it will copy tax way one of this function returns zero 333 00:43:36.780 --> 00:43:43.200 William Cheng: Okay, what do we turn to zero that means I didn't get to change from a one to chew and now is equal to zero, that means that a few times available. 334 00:43:43.830 --> 00:43:46.320 William Cheng: Okay. Few times is available. That means I should try to grab it. 335 00:43:47.280 --> 00:43:56.820 William Cheng: Right. So in this case, I shouldn't go to sleep right away is that occur. And also, since the few times available. I will not execute a system called here and then I'll actually this operation. I will change it from zero to two. 336 00:43:58.680 --> 00:44:05.430 William Cheng: Okay, so this goes over here, what I would do is I get, you know, temporary is equal to zero. So, I will use the calculation over the other departments. 337 00:44:05.640 --> 00:44:12.300 William Cheng: To, uh, to if it turns out this one return zero. That means I have changed from zero to a two and in this case I will read this case. 338 00:44:12.990 --> 00:44:17.910 William Cheng: Is equal to zero, then again I will return from few types luck over here, and I know that on the law. 339 00:44:18.900 --> 00:44:24.120 William Cheng: Okay, so every time these cars operation. You know, I guess when I changed it comma zero to two. So in this case, 340 00:44:24.540 --> 00:44:27.810 William Cheng: You know, it says oh god I still don't know whether somebody sleeping at a quarter or not. 341 00:44:28.260 --> 00:44:36.480 William Cheng: But guys, and this guy. See also. So, so I change it to a to then I own a few times so they applied we jump off your text over here now continue to execute with a few times lot 342 00:44:37.350 --> 00:44:48.390 William Cheng: Okay, if it turns out that this function doesn't return zero. Yeah. What should it be should return, you know, one or two and then I'm going to come back to the loop over here. Again, this little bit more sequels to one or two and then I'm going to do this thing over and over and over again. 343 00:44:49.710 --> 00:44:56.730 William Cheng: Okay, so I just mentioned before, you cannot use cast over and over and over again because in the end, going to be really nasty to the bus. So why is this co. OK. 344 00:44:58.380 --> 00:45:06.360 William Cheng: OK. So again, if you look at this code really carefully. Most of the time, what's going to happen is that, you know, sees going to be equal to two and then you going to end up calling a few types way. 345 00:45:06.540 --> 00:45:10.500 William Cheng: Or you are the feds going to change one to choose. Are you gonna end up a component to that way. 346 00:45:10.770 --> 00:45:18.120 William Cheng: It's very, very unlikely, you're going to end up looking like this over here for many, many times. Typically, after you leave for one or two times you're going to end up computex way. 347 00:45:19.110 --> 00:45:26.490 William Cheng: Okay, so therefore, again, if you don't like this very carefully, you realize that this code is actually in the end you will not be doing busy wait, okay because India. 348 00:45:27.270 --> 00:45:38.580 William Cheng: Very, very soon. You know, somebody's going to grab the few tags and now I have to go seek inside, Colonel. So therefore, my sooner or later it's going to come to you next week. Okay, so therefore I give up the CPU and I go sleep inside the cardinal now. 349 00:45:40.020 --> 00:45:49.860 William Cheng: Also by the way, again, this pretty tricky code over here at the textbook is run over here because I actually, I look up the original paper that talks about few types implementation. I'm verify that you know that that describes, actually. Yeah. 350 00:45:50.490 --> 00:46:00.180 William Cheng: So, so, so what about few times a lot, right. So again, we're gonna assume that you know when you computers along you are the one that on a few tasks. So in this case, what we're going to do that we're going to perform the atomic document operation. 351 00:46:01.050 --> 00:46:11.670 William Cheng: Over here is that the atomic document operation over here. So if we know that a few days is locked by someone about by me. So what are the possible value of the few tasks. It can be either one or two. Right. 352 00:46:12.540 --> 00:46:24.840 William Cheng: OK. So again, my thread is the one that on the few times. So therefore, the future value has to equal to one, which, you know, if x to the atomic document function over here if it returns one. What does that mean that means that my car has changed from one to a zero. 353 00:46:25.650 --> 00:46:31.920 William Cheng: Okay, so in this case I atomic a document. So that was going to become available. So therefore, my job is done. So I would just reach up a few times. 354 00:46:32.910 --> 00:46:38.670 William Cheng: But if they retain a body of two. So this one is not equal to one. So that means I've changed it from a two to one. 355 00:46:39.060 --> 00:46:44.730 William Cheng: Okay, so no case what I should do is that what what is the wrong value because I just unlocked it so therefore I need to 356 00:46:44.940 --> 00:46:54.960 William Cheng: I need to set it back to zero, and also because the previous value equal to two. That means that there might be somebody where he is out of Colonel. So therefore, in this case, I need to go and start a kernel and wake up that threat. 357 00:46:55.380 --> 00:46:59.370 William Cheng: Because in this case I will have to call few types way because there might be somebody said things that occur. 358 00:47:01.350 --> 00:47:11.100 William Cheng: Then alright so again this code is very tricky. So again, you know, you need to imagine the case but you have 100 CPU, they're all running simultaneously. They're all calling 359 00:47:11.340 --> 00:47:15.900 William Cheng: Calling few times. Like simultaneously and you need to convince yourself that this code actually works. 360 00:47:16.860 --> 00:47:28.050 William Cheng: OK. And then, you know, one somebody, somebody on a few times. And if we continue to running all the other CPU, they will basically they will all go go call a few times way. So again draw some timing diagram convince yourself that all those 361 00:47:28.470 --> 00:47:29.850 William Cheng: They will all go sleep. These are the Colonel. 362 00:47:30.840 --> 00:47:38.520 William Cheng: OK, and then eventually when our thread running over here. So now our third is the one that running with a pure tech blog over here. Everybody else is sleeping. Is that a colonel. What we've done over here, we're gonna 363 00:47:38.910 --> 00:47:46.470 William Cheng: We're gonna come up, wake up, wake up. A 30 so the colonel when that's a call woken up it will it will actually be able to grab a few tags and then we will continue to execute 364 00:47:47.400 --> 00:47:54.630 William Cheng: Because, again, this code is very, very tricky. I'm not going to keep going over this. Go. So again, if your question about this, please send me email. Yeah. 365 00:47:56.310 --> 00:48:04.680 William Cheng: Alright. So as it turns out that, you know, so, so somebody actually found a previous semester they actually they analyze this code. It's all kinds of 366 00:48:05.250 --> 00:48:09.030 William Cheng: Diagrams, and they actually send me email. They say, here's a scenario that it won't work. 367 00:48:09.930 --> 00:48:17.100 William Cheng: Okay. So as it turns out that there's actually a race condition in this code. Okay. If to have multiple threads over here, they all come racing into the CPU. 368 00:48:17.310 --> 00:48:22.320 William Cheng: There's a possibility that you're going to end up with a race condition and they're going to end up with a case where there's going to be a deadlock. 369 00:48:23.460 --> 00:48:30.600 William Cheng: Okay. So, so what I did is I actually pick up the original paper over here and sort of find out what the right implementation as, as it turns out, this is the right implementation. 370 00:48:30.810 --> 00:48:38.040 William Cheng: But the paper. The paper is right here. This is the, you know, you can actually dig it out and look at it yourself. The title of this paper is called few taxes tricky. 371 00:48:38.760 --> 00:48:47.310 William Cheng: Okay, so that's the name of the time that's that's the name of the paper. Okay. So if you look at a very, very carefully, it will tell you that this call only works if the colonel is atomic 372 00:48:48.480 --> 00:48:57.990 William Cheng: Okay, so when you make all the system calls you know a few tax rate over here and a few times of year where you come inside the Colonel. The Colonel has to be atomic with respect to the operation of this new tax. 373 00:48:58.410 --> 00:49:12.270 William Cheng: OK. So again, it doesn't have to be a you know a timing with respect to other few tasks, but for this particular few tasks that are the colonel needs to be atomic okay if that's the, you know, if you make that assumption, then, then there will be no there'll be no no no no race condition. 374 00:49:13.380 --> 00:49:19.230 William Cheng: Okay, but how do you actually make the colonel atomic so that's what we're going to look at look at next that so at this point over here. 375 00:49:19.560 --> 00:49:27.390 William Cheng: We are done with the few times over here. Okay, you need to convince yourself. This actually works. And you can assume that a criminal's atomic with respect to this free text. Yeah. 376 00:49:27.840 --> 00:49:36.750 William Cheng: I saw somebody of what we saw so far spin up is actually a very, very useful to block out another CPU. But what's required over here that you can only use spin up 377 00:49:36.990 --> 00:49:48.990 William Cheng: You can only use spin out if you know that the spin out will be locked for very, very short period of time. Okay, what is very, very short period of time while maybe on the order of microseconds, or something like that, even milliseconds going to be too long. 378 00:49:50.070 --> 00:49:56.520 William Cheng: Okay, so if you know that you were only holding a space for some reason you are sure that you only hold the spin that 379 00:49:57.060 --> 00:50:09.960 William Cheng: You know, for microseconds, maybe, though you are allowed to use us to spin up there. Otherwise, you should not use spin up okay and spill out is a sure way to lock out another CPU. Okay, so keep that in mind. That's the only way to lock on her CPU is used enough that 380 00:50:11.520 --> 00:50:13.920 William Cheng: The blocking law. We saw that it doesn't work. 381 00:50:14.460 --> 00:50:25.740 William Cheng: Okay, so therefore we're going to sort of find out some other solution and based basically what a sort of talk about the Linux illusion. I believe solution. We're going to start with your tags. So if you tag is the optimized version of the blocking law. It's a user space. 382 00:50:26.700 --> 00:50:37.530 William Cheng: user space on mute. So again, we're thinking about the one level model that requirement is that when you copy me on Slack. If the meeting is available. You have to grab it in the user space and we just saw the code for doing that. 383 00:50:38.040 --> 00:50:41.610 William Cheng: Okay, we don't really know how to make the colonel common yet. Right. But that's what we're going to see next. 384 00:50:42.780 --> 00:50:48.750 William Cheng: Alright, so you're close. I mean, number one, you need to implement Colonel flats, right. So, so even though the code for the 385 00:50:48.930 --> 00:50:56.220 William Cheng: The, you know, the colonel today, you just read, they all have the same thing that one of the first procedure and the first procedure or just regular C code over here that 386 00:50:56.760 --> 00:51:06.330 William Cheng: But the behavior is going to be very different. Okay. So keep in mind that the weenies Colonel is going to be non preemptive again what is non preemptive right number 300 meaning that 387 00:51:06.810 --> 00:51:17.370 William Cheng: Okay, so, so now we wasn't need to interrupt into it. Right. So when you have a cauterized non non Priyanka, that means that if you are in the flat contacts you can get interrupted and going to the internal contacts. 388 00:51:18.210 --> 00:51:22.950 William Cheng: That. But once you go into Iraq contact, you have to come back with Hong Kong back to the same to me. 389 00:51:23.580 --> 00:51:35.370 William Cheng: Okay, so this way you know what you're still running out of CPU as a threat. If you don't want to give up the CPU. You can only temporarily get yanked away from the CPU to service it, you know. But as soon as that we jump back into their contact you continue to execute 390 00:51:36.600 --> 00:51:45.750 William Cheng: That. So this is known as a number three and sip, Colonel. Okay, what about a preemptive Colonel, you have to cut on means that if you're a funnel that you're executing that kernel and you get a timer interrupt. 391 00:51:46.080 --> 00:51:50.610 William Cheng: Okay. And then when he comes back into the contacts that you know the colonel will be executing a different way. 392 00:51:51.720 --> 00:52:04.470 William Cheng: Okay, so for a preemptive Colonel your CPU site for for granted colonel colonel through I can lose the CPU anytime. And then, you know, the obvious isn't going to end up running a different a different way. 393 00:52:05.670 --> 00:52:13.200 William Cheng: Right, so, so keep in mind that your weakness, Colonel is a non parameter, Colonel. Right. So, therefore, when you're modifying data structures that are kind of, let's say you have modified wingless 394 00:52:14.610 --> 00:52:18.660 William Cheng: Ok we have modified Linda is right. My for to this link or something like that, you're going to be 395 00:52:18.960 --> 00:52:23.910 William Cheng: You know the I'm hooking pointer or something like that. And all of a sudden you get an interrupt is I'm going to cause you problems. 396 00:52:24.330 --> 00:52:31.380 William Cheng: Well, the answer will be no as long as this data structure over here is is not something that the interrupt service routine will touch. 397 00:52:31.890 --> 00:52:35.940 William Cheng: Okay, if it you know if it's something that you know observer something with Coach, what are you going to be in trouble right 398 00:52:36.210 --> 00:52:42.600 William Cheng: But if it's. This is a linked list at the end up serving. Do not touch then Robin is it you know of servers are things going to touch other data structure. 399 00:52:42.750 --> 00:52:50.820 William Cheng: When it's done. It's going to go back to exactly what you were doing before. So, therefore, you can actually be in the middle of modifying some linguists it's perfectly okay to get an intro 400 00:52:51.600 --> 00:53:00.540 William Cheng: Okay, because you know that you have a number of the Colonel, you're going to get returned to exactly what he was doing before. So you get to finish hooking up and I hope you live with us and and 401 00:53:00.960 --> 00:53:05.040 William Cheng: And then at some point you decided to give up the CPU, you have to call swish swish to be over CPU. 402 00:53:06.810 --> 00:53:13.620 William Cheng: Alright, so that's one major difference between Colonel threading user to air is that the kernels read over here, you need to remember the Colonel's number 403 00:53:14.280 --> 00:53:21.600 William Cheng: That all right. I don't think you need to remember is that the colonel is very powerful. How powerful is the Colonel. The Colonel is the most powerful stuff inside your machine. 404 00:53:22.290 --> 00:53:34.380 William Cheng: Okay, so what does that mean that if you have a bug in your carnal. Yeah, so therefore the colonel must be bug free, right, because if the if the total is the most powerful things on your machine and it has been done that. Well, then all bets are off. Nothing's going to work. 405 00:53:35.580 --> 00:53:42.660 William Cheng: Okay, so therefore you know the code that you have written so your kernel. It also needs to be bug free okay if your call has any 406 00:53:43.320 --> 00:53:50.340 William Cheng: If your car. Has anybody inside your code, that means that the colonel is gonna have bug inside of Colonel, so therefore it's in that case, you know, everything's gonna fall apart. 407 00:53:51.600 --> 00:53:55.440 William Cheng: Well as for some people, you know, actually send an email to say hey you know the colonel is not doing this and that. 408 00:53:55.950 --> 00:54:01.200 William Cheng: You know, why isn't the Colonel. The Colonel doing this and that was it was must be because you have a bug in your code. 409 00:54:01.770 --> 00:54:08.850 William Cheng: Okay, because the Colonel's and most powerful, you know, stuff that the savings on your machine. So the colonel is not doing that. Is it because you didn't want the colonel to do something. 410 00:54:09.600 --> 00:54:11.610 William Cheng: Okay. Some people said one of my favorite is not running was 411 00:54:12.180 --> 00:54:16.860 William Cheng: That's because you didn't give up the CPU right if you want that to be running, you got to make sure. So if you want 412 00:54:17.100 --> 00:54:25.140 William Cheng: To be running. What do you have to make sure you got to make sure that I was sitting around queue and they your, you need to give up the CPU, because if you don't give up the CPU that there will never run 413 00:54:25.500 --> 00:54:34.260 William Cheng: Right, because you know you're doing your kernel Simon, you are the Colonel, so therefore you are very powerful. Okay, so if there's any bugs. It's your bucks. 414 00:54:35.280 --> 00:54:40.320 William Cheng: Okay, so, so that's, you know, comma, power also company's responsibility, right, you got to make sure you're kind of bug free now. 415 00:54:41.430 --> 00:54:52.470 William Cheng: So, by the way, I'll call I'll send me one quarter one and two. You're completely inside the kernel space. There's no user space but but only in Colonel assignment number three, then you have to implement the user threat. 416 00:54:53.370 --> 00:54:57.930 William Cheng: That. So when we're talking about threat and processes in quarter one and two, we're only talking about Colonel 417 00:54:58.260 --> 00:55:06.840 William Cheng: Colonel policies. Okay. And please remember, we're doing MTP equal to zero. So every Colonel threads. Exactly. So every Colonel process have exactly one kernel threat. 418 00:55:07.080 --> 00:55:13.440 William Cheng: If you want to create another thing. What do you have to do you have to create a new process and you need to run a thread inside that process. Now you're gonna end up with another today. 419 00:55:14.010 --> 00:55:19.860 William Cheng: Okay. But again, that's where I belong to another to another process. You cannot have two threads inside one process then 420 00:55:20.880 --> 00:55:33.690 William Cheng: Oh, so this is a good time to break and next thing we're going to actually talk about how to make the colonel atomic we also going to look at a little bit of Eros. Okay. So that will be the last part of lecture 10. Yeah. All right. Don't take a break.