Today, we saw at the keynote a nice example of what is FPP and how it's applied in a Node.js environment, the Node Red. It's quite nice. Everyone could understand what is the flow, what it's doing, and how easy it is. So, I'm here. I would say who I am. The challenge and motivation that led me to the flow-based programming. What is flow-based programming? Soleta, the project that I lead. And the pros and cons to that. I'm a Brazilian guy. I'm a software developer since I was nine years old. So, I'm not that old, but I do software for a long time. And I think in terms of software, more than English or Portuguese or whatever, I work with Embedded since 2005. And I started with, like, my AMO devices, and then I did Tizen for Samsung and Intel and so on. I created my own software consultancy company called Profusion Embedded Systems. It was acquired by Intel in 2013. But this year, I'm out to recreate my own company. I have years of experience with event-loop-based programming. If you don't know what it is, I will explain. And I am the Soleta Arctet and Lead Developer. Okay, so IoT challenge. If you look at IoT, there is a big difference compared to traditional embedded systems. That was the topic of my research as a manager inside Intel. I had to investigate and see what is different and why it's different. So, basically, the difference is on speed of development. Particularly at this point of time where people still don't know for sure what the consumers will buy as IoT, they must experiment. And experiment means faster time to market. It means faster delivery. It means faster everything. So it's much faster than the phones. So when we think about embedded systems, we think about 15 years or more of deployment time. So costs must be reduced. But I have years to develop my product because it should last forever. But IoT is like I'm creating a nest now that should last for two, three years, unlike most thermostat that were built to last forever. Okay, so people need speed and people need some ease. We need some guys from the web and from the phone applications to migrate to this new development system. This is a problem because the web developer doesn't necessarily know what is an ISR and how to handle interruption service, what can be done, what can't. And the solutions that exist are focused on a single solution. So it's just for hardware access. Intel had a nice library called MRAA to access GPIO I2C. And then they created IoTivity that is nice for networking. How do I mix the IoTivity and MRAA with an HTTPP library or MQTT if I want to do more than one protocol in my software? So we need also a scalable solution. In the previous talk in this room, we had IoTivity constraint. There is one API that works on microcontrollers. Then you need to learn another API that runs on Linux. That's not that good because you need to learn two APIs. You need to develop two code paths. It would be nice to have something that is well integrated where I could reuse my knowledge, right? And that's Soleta. That's the Uniform API to abstract platforms so you know how to upgrade, how to store your files everything, how to access your sensors, and also how to do networking. So this is the Soleta project that is the base of this talk and why I came to this. So we were requested to create an easy to use API. To create an easy to use API, you must understand your users. Otherwise your users won't understand your API. So we started from the basics. How did we learn to program? Like when we did programming 101, what was that? And then look at the IoT workflow. Does it match? The IoT lifetime matches to programming 101. And this is how we start. We read input, we process that data, we finish. We report and finish, right? This is how almost everyone here started to program. Anyone started with a different kind of programming instructions. It's just read data, process it, print, and that's it. Finish your application, right? This is procedural batch programming. It's a single workflow and barely handle any kind of interruptions, errors. It's like you do, you pass the test, no memory freeze, allocations and everything. It's not that good for a real life, right? Because when we look at the IoT device, what is the lifetime? We expect to continuously serve multiple inputs at the same time, okay? From network, from sensors, from users, from timers. You may have a coffee machine that is doing like the coffee. So it's brewing, brewing from some sensors if I need to make the water hotter. And if the user press the cancel button or if there is some kind of network maintenance check, there's timers like cleanup timers. Do you want to fire the cleanup timers while you're bringing the coffee? No. So it is hard to make it work with programming one-on-one, right? When you go to novice developers like Freshman that came out of school and they want to work with you, you say, hey man, how to adapt these to continuous serving multiple requests? It's easy. I do a while one. I'm continuously running, not finishing. It's there, right? I fix it. Okay, but how about multiple inputs? You're just reading from one input. Easy, sir. We add like lots of functions, one at the bottom of the other. So we read from the network, then we read from sensors. But what if there is a sensor data to be read but there is no message from the network? You don't read the sensors. It's easy, sir. You go and you check if there is data.  But it's easy to understand. And that's why people come to this conclusion. Also, if process network data is reading from TCP and the guy did a huge batch of data to you, you'll be stuck there. So you'll be stuck into process network data or read networking input. However, you had a blinking LED or you had an animation on your UI and it stops. And the user thinks that everything is scratched or broken. It will kick the machine. It will complain to you saying that your product is bad, okay? So there's the last try. We create threads because thread solves everything. Threads are simple. You basically put the second solution in a thread, right? And I create three threads and it's all nice. However, what to do about shared resources? For example, I have a network. I have not a network. I have a UI and I have a sensor. They are on different threads and the sensor updated. I must update the UI. If you do from the thread, you break everything because the thread is not thread. The UI is not usually thread aware. So you run into problems, right? So you stop. You go research and you find the event-driven programming. Also known as main loop. That is pretty common on servers and UI. If you did a UI toolkit, you likely did event-driven programming. Okay? It is super simple because it takes the try tree. But instead of while one, it uses a while wait event. That is where the magic happens. However, the users, like for the naive developer, it's very simple. You just do a batch of ifs. It's all in a single thread and everything. You may even use a dispatcher table. Like here is all expliced. So if my current event is network, I do this. If my current event is sensor, I do that. Okay? You may convert this to what we are users doing. Like GTK, QTE, FL, like register event handler. When there is network event, you call that function. When there is sensor event, you call that other function. It's very easy to understand and people like it. Okay? Because it's very similar to 101. So they are used to that. The wait events may handle multiple input by using a thread or different primitives from the OS. But from the outside perspective, from the user, you are looking to it as a simple single-threaded application. It's very easy to implement with select, pull, pull. Timeout is also an event. So it's very easy to match and add more events, like network threads. And it suggests what we call idler. This is a concept where run this function where there is nothing else to run. So this is a kind of comparative task. Instead of having two threads where one thread is stopped at some random point for the other one to run, instead, you have a small function that will give its time to another function, and eventually it will be executed again. In more details. So at the top, you can see process network data, the traditional version 101. The programming 101. So when the process network data is executing, let's say it will take four seconds because of network input is big. Your LED, your light, is stuck into the on state. So for four seconds, the LED is not blinking anymore. It's on. And then times the function ends, times kick, LED will be off and on. Then you have double of data coming from the network. Then your LED will be on for double of time, like eight seconds. So this is pretty bad, pretty bad experience for the user. However, if you break your function into smaller functions, you may interleave with other tasks. For example, turning the LED on and off. So let's say you can segment each function to one third of a second. So you get many blocks, right? They execute the same thing, but usually it takes more time. As you can see in red, it's more responsible. So it feels faster to the user, but in reality it's taking more time.  So you are drawing pixels. If you segment your work per byte, you know it will be fast, right? But it will take forever, because you're throwing away all the cache lines, everything, it will be taking forever. So you need some kind of balance. So the overhead is not that much. However, the itch of instance is not that big, okay? Because as you can see, there is a space between these two boxes. This is the time to execute these tasks. So there is no magic. It's easy to do. Iblers, if you're not familiar with them, they are not that hard to do. If you have original code, there's like a four, that you execute the inner block. That inner block to another function, right? So you make the original function just a starter, where you register the process data idler to be executed when nothing else is being executed. It's like a background task, okay? And when it executes, then you have the context that you use it and you call the actual function. That is the yellow one, the process item. The time of process item is like fixed or short, known to be short. However, on the original code, the count, the number of times that fixed amount of time will be executed is unknown because you are getting that from the network. You are getting that from some sensor, from configuration file. So that is a problem. Then there are pros and cons. Pros, no real concurrency. Four locks, no deadlocks, okay? It's very easy. It works everywhere. You may get the crappiest OS on Earth. If you have like a bare metal, it will work there because you don't need any kind of special help from the OS. And it's very lean on memory. If you consider this compared to a thread, here your context is not a full 4K stack, right? It's like one pointer, one integer, and then another point here, right? It's small, so it's very lean on memory. However, it requires you to manually analyze your code, and most people get that wrong or they are afraid of doing that because you are taking one algorithm. When there is a simple 4, it's very easy, right? But for more complex stuff, it gets out of hand and most people have problems doing that. You need to maybe recreate your algorithm. It requires callback and extra context, so it's more to remember and more to manage it, more to leak, more to crash. The consolation and error-rendling must stop the idler and free. Gustavo, this is easy. I know, as you did here, you call idler stop, and that's it, right? But take as in consideration when you read data from a network and then you decode that data and then you process it, and then in the middle of that, you get a consolation. You must know where you are. You may not have just one consolation. You may have multiple requests at the same time, like three network requests that you are doing in parallel. So instead of a single pointer, you are keeping a list, you must find what to cancel, and it gets out of hand, right? It's painful. So the Soleta project and the initial choices. We had to focus on scalability, so we had to run on very small systems, like microcontrollers. We had lots of previous experience with object orientation in C. We had lots of experience with main loop, event-based programming. I'm an EFL developer myself, so I did that for my most whole life in programming, so it was very simple to me, right? And we did network sensors and actuators on top of that. However, as expected, the same design led to the same problems. We had to test if our API was easy enough with random dudes, not just my-offs, but some random students, hackerspace and everything, and we got to the same conclusion that most people don't get callbacks. They get it wrong, okay? It will lead to segmentation fault, to leaks, and the boring parent. On-event, get some data, do something. It is error-prone, okay?  And investigating, we found the flow-based programming. I wasn't familiar with that. I guess that... Who was familiar with flow-based programming here? From where? LabVille. LabVille? Okay, it's a good one. From circuit and from electrical engineer, I'm usually more familiar with that. Guys from programming, like, who started from COBOL or whatever, we start to learn how to program in traditional batch-oriented. But if you look at this, it's easy, right? In this example, I have an action that should be executed on a timely basis that is configured either by a dialer, so you have a dialer where you turn, like, 5, 10, whatever, or an HTTP server. So here, if you look, it's very easy to understand. If I have a dial output, it will be persistent. Persistence. The persistent data will come back to the dialer, so it's updated and to the server, so it's also updated. So you feedback the information and you also change the timer so it will use the new value and the action will tick, okay? So it mostly, everybody gets that and it's easy to explain, even to the non-programmers, like UI designers or your manager. So the flow-based programming was created by Joe J.P. Paul Morrison in the 70s, so it's very old. He says some banks in Canada and things like that use this system, so it's reliable. The idea is that you base your code or your architecture on black boxes.  So ports. Input and output ports. They produce or take information packets. That's the data, right? The sensor is on or off. If there is a string, if there is a color, if there is a temperature, things like that. It started to gain traction in web recently, so there is this no-flow. It's a very nice project. It's written in Node.js, but there are also the big guys doing that, so Facebook Flux, Microsoft Event Hubs, Google Tensorflow. And also on embedded systems. If you've ever heard about ROS, the robot operating systems, it's all about you have some boxes, so this is the stabilization box, this is the image tracing box, this is the GPS, so you link them all and the robot works. There is a nice one called MicroFlow for microcontrollers and Node Red, what you saw today at the keynote. What is the problem with these guys? ROS is kind of big. MicroFlow was kind of limited and Node Red is based on Node.js, so it won't run on a microcontroller because it's like JavaScript and requires the full Node stack. Multimedia guys also do that. Video for Linux is a flow-based programming, Gstreamers like that, and Apple Quartz. So concept and terms and our translations to Soleta. So you have the domain-specific language at the top where you write Node 1, this is your variable, this is your instance, right? It's the, officially it's called the process. And you have the type that is your class or your node type as we call it. And you have the port, the output port that is connected to an input port of another node and of another type. So it's text description. It's pretty close to the actual graphical description. And it's even easy to convert, so it's very easy to read and to understand. Here, the focus is on the IP, the information packet, or just packet. You don't care what is inside Node 1, what is inside Node 2. All that matters is that I expect an integer to come from that when it changes. So Node has black boxes. It's a very simple interface. It's almost no coupling or it should be no coupling between the components. One box doesn't share with the other box. All the sharing is done, should be done by the connections and information packets. So that allows you to just replace, like in this, you could replace dial with some scene. Like in Soleta, we allow you to just replace that with a GTK button. So you could get a GTK spin button and then you request your peer, hey, you now implement something that delivers that based on a hardware. So I choose C plus GPIO plus whatever. But it's very easy for you to replace. It allows you to optimize code because each port, if it's not used, it could be removed. You can do that with pure C or pure C plus plus, but it's harder. With this kind of analysis, it's easy, you get an FBP, you see which ports are being used and you can drop all the other functions much easier. It allows for a parallelization. That means you can easily move each box its own process or its own thread. What it takes? Just you work in the core. It takes no effort from the user because each box is like a black box. So if I'm sending that package to that box in a different thread or in the different process, it shouldn't matter. We know that reality is a bit harder on us. We have shared resources like underlying libraries. You may have a HTTP node that shares the actual server and socket. So you have some constraints in real life, but the idea is that you could potentially move that to a different process without the user having to worry about that. And also isolation. So you take a third-party model, you're worried about that, you don't want that model to do any kind of ping back home or take too much memory. What you do, you easily move that to a different process and put an IPC in place. All that you care is about data. So the IPC is very simple. IPC using unit sockets for the basic data types. So this can increase security. You can apply like SCE or SMAC labels to that to that process and reduce capabilities, reduce quotas like CPU quota, disk quota, even have a different user.  So you can do threads. The only constraints that you need to cooperate with the packets and deliver them from the main track. And one nice thing is if an FBP program crashes, it's guaranteed to be the node fault. So the outer of the FBP. On the other hand, you can see this from a different perspective. It's impossible for the user to crash your node type if you did proper testing. Toss over there is a friend and we do lots of EFL development where we call back the user. What happens when the user double-free from the callback? It crashes. And he sends you the back tracing saying, Gustavo, this is your fault. Because here we have EFL whatever here and EFL is your code so it's your fault. EFL is just the main loop. It's calling you back. It will be in all back traces. However, the users don't get that. They take time to understand they did the double-free and trying to find out it's hard. But here there is no way to double-free or to leak memory. The only thing that they can do is connect where the information goes. So if the information provider or receiver is well done, well tested, then it will never break. That's the thing like kernel. If you break the kernel, oops, it's the kernel's fault. It doesn't matter what you did if you did a mistake in the user space. It's always the kernel fault. And it's all about information packets. So what goes where? And there is a clear data ownership. The data, like when I do a GAT you provide a GAT of some data like a GAT of a string. Who owns that string? Maybe you can annotate that and having some documentation saying don't free that memory. It's an internal reference. But users may do mistake. Here there is no mistake. You create one packet, you put it in the queue, it's not yours anymore. It's owned by the core. So the core will deliver and then real free, no leaks. And the memory management then is hidden in the core. The core is free to queue, to reuse packets. Callbacks are also hidden in the core. So if you look at our implementation it's full of callbacks but the user won't see them. Like when you send a packet you are basically calling the callback process of the receiving node. That's a callback, but the user never see that. And packet deliverer can be delayed. That means you can put the CPU to sleep or queue that for a while. So you don't busy loop if you don't want to. Packet memory can be recycled so you can have a fixed pool of packets. And you can even deliver calling or something if your queue is almost full. So you don't overrun in memory. Seconds can be typed. That in Soleta, for example. This allows you to pre-validate if it's going to work or not. So you don't need to go and flash and get the runtime error. You can get that in compile time as well. That is something that you may say, yeah, but that's also the case with C. But usually if you may take a different set of values in C go with a void pointer and a size or a type. The user may not check that and there will be a problem because the compiler won't tell you. So you are sending an integer and I'm getting a boolean. It will crash. Right? So for Soleta FBP what is the specific in it and why we did like that? Basically we had to focus on scalability from microcontrollers as the units end up. We had to make it extensible like microflow was nice but it was kind of fixed. And we had to focus on configurations because as people are trying to produce more hardware they are changing the hardware more software products, they are changing the hardware. That means that for product A it's almost like product B but that changes the sensors. So it still produces a binary but here is GPIO and here is USP. So we had to be careful with these configurations and a low easy configuration. For more details we can look at Ivan's study its flow-based programming on our wiki but going for things that matter we are statically typed. Why? Because we want to have more information to optimize on small MCUs. We still don't do all the optimizations that we could but we run very low on memory. So I can share with you that we have an OIC with Zephyr running in 100k of flash 32k of run, total. So the user didn't write one single line of SQL, just an FBP OIC client GPIO for LED and a button and it will work with not that big overhead. That means IPv6 UDP OICC board overhead that the networking technology brings. We type check at both compile and run time so we have an FBP generator and FBP runner that I will show you how they are used, we check at both. We have a series of predefined packet types so Boolean, integer, string, vector, caller but we also allow you to pack them in a single unit so you have three integers and one string that's okay, you can pack them together into composite packets and of course you can provide domain specific packets like I have an image I have a sound, I have an MIDI things like that, you can create your own packet. You don't need to serialize to a series of caller packets so packets are immutable and because they are read only you cannot change them that allows us to deliver the same packet to multiple connections because that's an extension that we created as well so you may be connected from multiple ports if you're an input port and you may be connecting to multiple output ports so this is one nice thing that we do on-send the flow core owns the packet so it's not your anymore you don't need to care about memory management anymore we are going to do that for you each deliver happens on a different main loop integration so if you have a feedback loop like this this is a feedback loop right from dial, persistence and then back if you do this naively in C it triggers an infinite recursion it will blow your stack but we don't have that problem because each function is called from the main loop so the stack is kind of low and you can do this feedback loops very easily we also as I said allow multiple connections to and from ports and the ports can know who is connected by providing the connect and disconnect methods or callbacks so these allow for things like I have 32 ports and the user just connected 2 ports should I wait all the 32? no I need to wait just for 2 ports to provide the result at the end so you can use connect and disconnect to do things like this and of course if you are taking packets you must use the process function that is your entry point this is per port not per node type so some solutions they queue all the packets for you like they put in an array and they call process and then you pick from each box in our solution you are called for each of the packets that come in you are free to reuse or do that internally if you want but this is how we do so the usage workflow you may write your own sql then compile that's the canonical execution or you create a source flow-based programming that is the DSL that you can use together with a solflow board.json that is a per board configuration that I show you and from that you have 2 paths one you can generate code then this generate file is just like this one goes to the final binary or you can execute it just like javascript or like python this bottom is only available on powerful systems like linux you need more memory you need introspection and things like that here at the top we just generate what we call the information so there is no json parsing here in the generated source there is no string when you see out in this binary in this source in this binary there is no out written in it we resolve that to a port index so the dispatching is pretty fast we have at the end two arrays one array is of the node types so this is my objects you create it like this these are the options and this is the type and then you have a connection table like a telephone where you say object 0 port 0 goes to object 2 port 1 and that's what you get so it's very simple and it's very fast to execute and the configuration is a unique feature from us the idea is that you can generate configuration files per application per board and per application and board you also have a fallback here so you can provide things to test on desktop for example this is the case when you have a board with a GPIO that is a given number the second board is a different number of GPIO the other board is not even GPIO anymore it's a keyboard and then you want to test that on your PC then you want a GTK button to show where you can press and it will simulate for you with this configuration file it's very simple to do it's automatically you just have to create a JSON file say the name, say the properties and that's it you can run or you can use that configuration file in the FBP generator that is useful for cross compiling so I'm compiling for a board with Zephyr and Ironboard but I'm running from Linux I don't want it to use the Linux file so you can manually specify and it's even auto-detected if you're running on Linux it will use a series of regular expressions from a JSON file and it will detect this is a big old bone black so these are the sets that I should be using this is an Intel board so these are the settings that I should be using it's very neat our node types are components what goes in here, in blue so they are very simple they are a C structure or a pointer to a C structure with an open and closed that's basically the constructor and the structure and an array of ports that's it you can reuse these objects even outside of Soleta you can use a libsoleta.so so you can have like a timer it's a built-in node type it's inside libsoleta or you can create an external .so that Soleta will find automatically based on the name or you can put that into your application you don't need to install that on your system or in the case of static-like applications, you use this option the descriptions are meta-information what is the port name what is the port type this is all compiled you can compile that out so on microcontrollers you are not getting that information to throw it away and you use the FBP generator to resolve that into C code and then you just compile it or you use the FBP runner that is very easy to use you can try it like you do in Python or Lua or Node.js you can even create meta-types or you can create types by using meta-types we have a type that allows you to a meta-type that allows you to create based on FBP so you use a FBP as one box into another FBP that is easy to split your code and organize your code you can create the meta-types for composite types so how do I split and how do I merge them and even JavaScript you can create a Node-type written in JavaScript and we also have Node-type options so the traditional versions of FBP do something like this they call initial packets so you have a Node here like a GPIO and you want to set the pin number to 1 and active load to true we convert that to two options the first option is to specify the options in the Node and the second one is to create a configuration file as I told you before like my GPIO and then when you run it says what's my GPIO I don't know so you look into the configuration file so the environment variable matches my board one or the regular expressions we pick the my board one and we look oh my GPIO it is a GPIO reader with pin set to 1 and active load set to true so you don't need to change your FBP at all you just reuse your FBP with different configuration files including on desktop you may use the GTK or keyboard and console to make it easier and this external configuration is something that we like very much because we had to deal with Zephyr boards running Intel Quark SE boards running Zephyr and we had to manage some Mino board Galileo Big O'Bone Black all the kinds of Linux boards and they were all different in pin numbers and everything so the cons paradigm shift it is very hard on experienced developers if you are used to think about procedural programming regular object oriented programming you are going to have problems I won't lie to you we all had when we started it was new to all the developers so we had to learn it and we did lots of mistakes the biggest mistake was trying to synchronize things that are not synchronous for example we have node here node there they are exchanging one information information inside that pipe inside that connection is synchronous however if I had two objects providing data to the same object if this data was generated before that data it doesn't mean that this data is getting in before it may be reordered across channels, across connections just inside one connection it is guaranteed to be linear and why that was a problem because people start to do hacks like this node and I have another and then another so this adds a hop it will delay the package delivery right so this one was like a straight line so the package arrived earlier so what people start to do let me add a hop here just to delay and let me synchronize it and then boom because that delay may be like a bigger node that will delay for three iterations not just one so it was us getting it wrong and learning with the mistakes so the paradigm shift is not that easy on experiencing a developer however if you get the naive developer, the freshman guys from non-computer areas like kids they get it right and they they are not stick with the information and to the paradigm that we are and it requires bindings so if you want to use another library you have to integrate that it's not automatic it's not like include the C file and that's it you need to create a node type and you do that in C of course and you need to expose this manually it's like doing a python bindings or java bindings or lua bindings we do add some overhead there is no magic there is no free lunch but we believe that the overhead is not that much it allows us to run on very small boards already and you need a balance to see what you are going to write in FPP and what you are going to write in C clear example we started with the basic node types like this is a addition, this is a multiply this is a comparison this is an end and that's it ok so let's write Fibonacci Fibonacci canonical example should be very easy but it's not it's very easy to get wrong and then you start to look and lots of mistakes, lots of people trying first it's not simple and it's not efficient because what should be a straight algorithm in C using all the registers you are now creating packets sending packets queuing going back to the main loop so it's not efficient however it is easy to get this wrong and do things that you should be doing in C in the node type trying to do as an FBP sometimes it's valid because it's just a proof of concept you are just experimenting then you can do that but you need a careful balance to see what you are going to provide in node type and what you are going to use in FPP the pros are much bigger in our understanding and that's why I'm here we have no leaks, no segmentation fallouts, reduced blaming it's just by itself it's worth but also it makes it easier to collaborate across teams so if I need to create an API and give it to you so you can implement it's not that easy, right? people get it wrong, you are dictating my design and so on this is not the coding style but here the interface is this is the data that I get in this is the data that I get out that's it so in the case of the dialer here I may just use like an HTTP server again or I may use a keyboard or something and I give it to you and say go and implement that using I2C SPI I2C, GPIO whatever I don't care this is my contract, I want an integer in integer out, that's it so it is very easy to collaborate with different teams it's also very easy to read, write and visualize we even have a tool to convert to graph viz so you can get a plot we don't have a visual editor like Node Red guys as they do we would love some people even started it but they abandoned that but anyway it's very fast to prototype and to test so as developers we started to use FBP more and more to test our code first FBP the inner code must be asynchronous so when you design this API sometimes you miss that so you have to review in the next iteration if you try to do the binding binding for FBP you get it right and then you get the benefit it's much easier to test so we have lots of tests in Soleta code and lots of samples that you can use as a base to learn Soleta and that's it, thank you you can check our OIC tutorial at the github it explains to you how to create to very simply create a switch and a lamp using OIC with Soleta so 0c code is just putting together some FBP drawings and some explanations even on how to read errors like if you did a mistake if you did a typo then it explains to you how to read error messages and all we also have, I don't have in this talk but I had in a previous one a tool where you can have Node.js application to run on board then you get the browser you type the FBP and you can run, of course our samples without having to install Soleta on your PC or your cross-compire to your board so one question someone has a question and then it goes to the but at one particular time how do you manage the the concurrent the concurrent realm and the derivative is the concurrent realm where if you are in between the thread save or whatever ok so mapping that to flow the flow is not meant to be doing at least our implementation of flow is not meant to be doing real-time tasks ok so what Soleta does Soleta is a project not just the FBP we use a main loop internally so all the interruptions we queue to the main loop and dispatch later so everything is dispatched to the user like I don't want to use FBP I think it's crap but you do have a nice abstraction layer like it's a glib or qt for IOT so you run code on Contiki, Riot, Zephyr and Linux ok I want to use that you are never called from ISR we queue that so it's delayed so what we recommend that drivers like I have a component you do the drivers in the kernel if it's Linux if it's another OS like Zephyr they are taking the same approach they have a sensor framework that is like a sensor subsystem where you can use that and you can provide stuff in there like a thermostat and things like that so you do it there what you expose here is high level so if you think about a company you have guys that are creating the business law guys that are creating the like the drivers guys that are creating the actual the their total subsystems so these guys provide libraries to each other like the drivers guy provide some libraries to these guy writing the no-types and I'm just linking the box together in a very manager and designer understandable way so it's all about macro blocks okay you are not doing like the driver in FBP itself you can try to do that but there are no real-time guarantees and nothing so you may run into problems however for quick tasks maybe it's doable so we don't block you doing that but it's not the recommended way does that answer your question? another question someone? nope okay another one the way that we do is you need explicit connections and what we do is we have an array and we walk that array from the main loop so it's like this I'm at index 0 and index 0 is your node so I'll get the packets that guy sent a packet put in my queue like sending queue and I check this packet must be sent to this and this guy this one is you so I say hey it's your time I call your process function you process that you are not allowed to keep a reference or modify that node that packet you may clone that you may copy it when you return I'm going back to the main loop so if there are some events like network stuff I will do and then I'll go to the next one if you send some packet that will be queued so I'm not looping from you to you again I give the time for the other guy and then I'm back to you so this is how it's done I have this Soleta this other presentation that will also be online here I have more details and even an explanation is the FVP syntax in more depth and the size like what's the size overhead it's not just our overhead right because this includes the OS with micro IP UDP 6 low pan radio drivers GPIO driver and everything C-BOR co-app but you can see it can be very small and efficient so we have 32K this hardware had 80K of RAM and in this hardware nobody could run the JavaScript in it so we really think that JavaScript is another great solution that's why we want to allow you to write some no-types in JavaScript particularly for prototyping so as I said I can define the no-type writing in JavaScript to experts go optimize this measure take like months I just need 2-3 days to do my prototype and then you take months to optimize that so it is a good approach ok and I believe it's time out so we can go drink some beer thank you guys


Good day, fellow investors. I continue with my summaries of Warren Buffett's letter to shareholders in 1983. He summarizes his investment business rules, the key business rules, and I have summarized seven of them for you, which are great for having the best investment mindset. So here we go with Buffett's seven business investing rules. Number one, make sure the management is focused on improving shareholder value, not their own value. So stock market compensation, option compensation schemes, buybacks, etc. usually improve management value. As Buffett would say, we do not view the company itself as the ultimate owner of the business assets, but instead view the company as a conduit through which our shareholders own the assets. Number two, investment managers have to eat their own cooking. So as he says, most managers have more of 50% of family networked in Berkshire, so they eat their own cooking. If you invest with somebody, always be sure, make sure that they invest alongside with you and that they eat their own cooking. If not, please you will be screwed. So if your banker doesn't have his wealth in the same assets he's trying to sell you, run away. Number three, diversify but do it over time. Our preference would be to reach this goal, his higher than average American return on business investment goal, directly owning a diversified group of businesses that generate cash and consistently earn above average returns on capital. So in the 1970s Buffett was building the insurance part of the business. Now in 1982-1983 he added heavily to cigarettes and food because he found those to be the best investments. And if we look at his portfolio, of course, Geico is still the highest position but at very low cost, almost a 10-bagger. The second position is general foods and the first most money invested position is RJ Reynolds, the cigarette company. So he diversified over time and he buys what is cheap when that is cheap for long-term investments. On debt the rule is long-term fixed rates. We rarely use much debt and when we do we attempt to structure it on a long-term fixed rate basis. Why is the fixed rate basis so important? Because it gives you one less thing to think about. If you have to think about where will interest rates go, a year of inflation, a year of higher interest rates might make you do the wrong decision. If you have debt fixed, that's one thing to think less, limits your risk and you can manage other fixed things of your portfolio, of your investment portfolio or wealth differently. Number five, measure performance long-term, five to ten years. As he says, we will continue to apply it on a five-year rolling basis, even better if you measure it in a cycle basis. From top tick cycle to the next top tick cycle, who did the best, which changes things, which requires patience but is very important from a business perspective. Don't ever issue equity. He says that they issued some stock and they will issue. However, he was young and foolish in the 1970s, 80s, 90s with dexter shoes and I think it is something he regrets. So also from my business perspective, never ever issue equity if you really must not do so or it's a really big advantage to you. Number seven, a very, very interesting decision. Never sell a good business. You should be fully aware of one attitude Charlie and I share that hurts our financial performance. Regardless of price, we have no interest at all in selling any good businesses that Berkshire owns. And this is because when you own a good business, the long-term returns that that good business will offer are unlimited, no matter the current price and the market and nobody can price that in. So a business that will grow with 10% over the next 20 years, 40 years, the value of that business is infinity. And that's something Buffett understood back then. He kept his businesses as long as he could. We have seen the Washington Post, he held it for 40 years and only then sold it to Bezos. So simple, good businesses will deliver forever, high earnings, higher dividends, high returns on invested capital. No current price can justify selling that. Thank you for watching. If you enjoyed these seven short, simpler rules, which are also the mindset of this investing channel, where we do stock analysis, and we focus on having a good, rational investment, value investing mindset, please subscribe.


Max Mann is here with head coach Dave Gage as the Mustang split with LVC today. Coach, give us your overall thoughts on this challenge that LVC brings you. Yeah, I mean that's a championship team over there. Obviously they're, you know, they won it last year at the top of the standings this year, but I thought, you know, what we proved today is that we can play with anybody and that's something that I'm really proud of our guys. Obviously they took care of their field yesterday. We competed, making it close, but I really thought that we could have played better and we did that today. I thought the first game, obviously they came out, put a couple runs on. They had a good plan, but Sam Settlin did a good job and we kept battling and I think that allowed us to prove that we could go out here in the second one and then Matt did a phenomenal job in the second game and all around Billy set in the tone with the play, the very first play of the game, diving play. Just thought it was a really good win that second game improves it. Again, we could play with anybody. Speaking about that fourth inning, we had some runners on, and you faced a little bit of a contest there. How did you get out of that and come through with the win?  I thought Matt was doing a phenomenal job hitting his spots and Trent really does a good job back there receiving it.  You got to hit spots when you face a team like that. You can't throw the ball over the middle. You can't throw the ball bell high and we did a good job. And, you know, I just wanted to get behind our players and make sure that the umpire knew that I thought it was a strike. That was all right. All right. And now we face Hood and number two Salisbury this week. Give us a little preview on the week up. Yeah, big ones against Hood this week. You know, obviously we did a good job last week at home, but as we know, every game starts 0-0. Doesn't matter, you know, what the score was last week. So we got to prepare. Hopefully everyone will have a great Easter and, you know, good practice on Monday. Prepare for Tuesday's double header against Hood. And then, yeah, you know, Salisbury, again, we want to be champions in this program and we play, you know, number two team in the country, Salisbury. They're going to be good, but again, I believe about our guys. All right. Thanks, Hood. Thank you. It's free in Matt.  Is it all right? Matt, congratulations on your third win of the season. Thank you. Talk us through this game. You only allowed one hit and your team got enough to make the win happen. Yeah. So we got off to a good start. We got on the board first and pretty much from there, my defense played fantastic behind me. I don't think we made any errors behind me. So, you know, I just want, I really wanted to get this win for us. We lost two close ones to them earlier on. And then, yeah, this win was huge for us. So it felt good. I'm talking about that fourth inning a little bit. You're showing some frustration out on the mound. Coach Dave Gage is seeing some frustration. Just talk us through how you get out of that inning. Yeah. So I know I got a little frustrated with the unpowered. I thought I was making some good pitches. He wasn't giving me the other calls for, you know, I just battled through it.  But yeah, I just felt good to get through that and just competed through it and got the guys out. Congratulations, Matt. Thank you very much.


All right, welcome to winter and ECE 353 so can everyone hear me okay ish You people at the back might be a bit screwed with the tech size so you might want to move up to a little bit so Welcome back. Hopefully you had a good winter break and start off. Hello. I'm John I guess my full legal name is Jonathan, but I don't need anything like super fancy Do not call me my full legal name only my parents call me Jonathan when I royally screwed up So I don't want to hear that name. Just John is fine nice and easy Real real easy. That's it. So I'm a teaching stream professor. I'm fairly new. You may not have seen much about me I've only taught at UCLA before this and then here I taught the same course in fall So I've taught this course once before so you're not completely screwed, but Your only choice is me and I'm setting your exams now for a change. So good luck It'll be fine. My exams are usually okay. Don't worry about so Today's lecture. We'll talk about you know Just boring course stuff what to expect and kind of what is Changing with this offering if you've seen it before and seen that the labs are terrible Hopefully, I'll do something to adjust or address that So corcus is the main hub. I don't really like corcus. So all it has is a collection of links. So It all only really posts like scheduling announcements on there like when your midterm is so it emails you other than that Corcus is not terribly great So I'm not going to use it and your grades will also be posted there and that's pretty much all you will use corcus for I'll post all the materials on my website. It'll have links to everything and if you guys like qr codes There's qr codes, but if you download the slides from there, everything is clickable that URL is the materials URL in the corcus thing and Everything should be nice and easy So in a departure, I'm not going to use piazza. I don't like piazza. I like discord so we'll be using discord for Discussion lab discussion Q&A's my philosophy behind that is it's nice instant you get instant feedback and You know piazza is okay to like search stuff for but I want everything there for you So I'd rather just revise the materials if they are unclear Rather than just having to rely on like go References piazza posts it answers your question things like that and also in a departure We will It's also there's a chat if you prefer to ask questions that way So it actually pops up. Hopefully this works. Oh wow. Hey look it works So like 25% of you are already on discord So just go ahead message me who you are So I actually know you're enrolled in the core course then you should see the lecture's channel and everything So that lecture's channel will just go there So if you don't want to raise your hand or do that you don't are comfortable with it Whatever or you just want to add some reactions like something is really clear if you just want to like I don't know do that a bunch of times whatever that is that is also helpful and Then so we're going to actually be doing code submission how real software engineers do code submission not Uploading a zip file or a tar file to some random server We're actually going to use git and use an actual open source git platform So we'll be using git lab. That's the URL for it again link through corkis like 25% of you have already Logged in on this so that is good. It just uses the normal Toronto off thing And you shouldn't have to do anything special or email me on like discord And that's how all code submission will be done Labs are definitely going to change and I'll talk about that later But all your code submission will just be you're using git if you're unfamiliar with git you will learn learn how to use git and That's your your code submission is you push your changes and that's it So lecturers will also be streamed with vods So you don't have to worry about you know panicking and taking down notes if you don't want to you can go ahead Watch it again If you want or if anything is unclear, so they'll all be there.   I can see you like I can see your face It's not that hard to read while if it's just online I don't know if I'm doing anything good or anything bad or what? So and then also here There's the discord or you can feel free raise your hand at any time if anything is unclear And I will try and address it So office hours, I just tentatively set for Wednesdays at 1 p.m. Let me know if there's any conflict I guess discord would be the best place for that. Is there any immediate conflict for that? No Okay, nothing so the TAs and I will otherwise be in discord Most people get their interaction through that way because you don't have to wait for a single hour a week And I'm generally pretty active on it So but and of course office hours aren't going to be streamed or recorded That's for you resource only for you and of course is that office hours don't work You can just email me to meet on something else like zoom or something like that or other office hours So that's completely up to you So there's going to be at least plan for six labs a midterm and a final I Don't know if this will actually get approved by the department. They actually haven't approved it yet I was told that This might not get approved because basically what I did is use their system made the final exam the lowest percent It could possibly be then did about half of that for the midterm and then put all the rest of the grades towards the labs So it's like 48% labs 52% written so I was told by some other professors that it might not slide But the automated system was all full of green check marks, and they haven't emailed me back yet, so but So hopefully this stays intact and the finals a bit less stressful with this with this marking scheme, but this is the plan marking scheme and You might have heard before that the labs are like really really awful and really really time-consuming like 20 plus hours 40 hours something like that So the main my main job this semester is to make all new labs So all the labs will be brand new Which means you can't search them on github? Which Yeah, I won't say the exact percent but a lot of percent Last semester got caught for cheating for doing that. It's generally not a good idea so You can't one you can't do that to we can check it against you know your other students and Well, since they're all new labs, it's not going to be that much out there. So that's it So hopefully yeah No labs are just by yourself So you can talk to each other about the labs, but you can't you know debug other people's labs the lab Okay, yeah, and the practical sessions will be the TAs will be there to help you with your labs But there's no mandatory anything for them they're just going to be there to help you and that's it and There will be no TAs there on Friday So this Friday won't have any TAs because there's no labs I'll be releasing the labs and they'll be due on Mondays So next Monday will be when the first lab is released and then you'll have two weeks for each lab And they'll just keep going on and on like that until the semester just kind of ends so that's the plan for that and The also intent towards that is hey lab six is due the Monday of the last week So you should actually be done all the course stuff and then you can actually like study for exams And we can use lecture time for final review or something like that So I have to mention academic integrity Toronto takes it really really really seriously They even have like public hearings that you can go see people that got their degrees taken away and all fun stuff like that It's all public if you get bored on like a Sunday I suggest reading it some of the cases are actually kind of entertaining and I didn't know they took That seriously, but hey they do So technically this also includes not posting any code to Github and I will especially be enforcing this because I Don't want to see my assignment stuff posted on Github I know students kind of like to have their Github full of stuff that employers can see But spoiler alert employers don't care about your course code they assume that you have done it and they can read it in your transcript and Because this course is core to everything you can do something based on the labs that is actually an original piece of software that does something interesting and It won't be that much different from the labs and you can actually post it on Github and employers might actually care about it Because it's something that's useful So yeah Yeah Yeah, so if you take a little snippet, that's fine Generally and if you have a little snippet in your code no one's going to go see you know your I don't know your shell Project and steal a little piece of code from it like realistically little code snippets. There's there's stack overflow There's anything there's not going to be anything to do with that So the code you write is your code, but don't post my full assignments So you can study together can't do labs together. They'll be individual and The idea of this course and as we'll be doing in the lectures is making mistakes all the time and Making mistakes especially for this is how you learn if you don't screw up Then you probably haven't actually learned anything Unless you know you're like a one in a billion person, but I've screwed up lots of things We're going to screw up lots of things during the lectures and it's going to be lots of fun and then Don't try and cheat it makes your life hard it makes my life hard It makes the university's life hard Let's just try and have a nice fun course if anything sucks generally I'm quite fair about it, and I'll make some adjustment if I need to yeah. Oh like feedback for the lab grade so It should be mostly automated testing and then there's going to be a TA assigned to each lab that will be able to That runs a script and might monkey around with it and be able to answer any questions for you So there'll be test cases. You'll get the same script probably I haven't decided or not whether to do hidden test cases But you'll get a script with some test cases and it'll say what they failed and why and then you can fix them Okay So there is a few textbooks that are optional they complement lectures I try and make everything as self-contained as possible, but this Textbook this operating systems in three easy pieces is quite good, and it's free online PDF don't have to pay for it Yep. Yeah, so the question is how long do the labs usually take and the answer is I haven't made them yet So I don't know Hopefully like you have two weeks for them. So 10 ish hours instead of 20 maybe 15 depending on it, but Usually with these labs, it's like very Inconsistent your lab time because sometimes you might just get a bug that just screws you over for like three days and One of your labs might just magically work So but ideally like 10 15 hours not 20 Yeah, like 10 to 15 is ideal Probably be a much shorter generally if I can do the lab and under like an out in under my train ride Then it's probably okay, which is like an hour 40 But I'm probably a lot faster than you so like 10 to 15 Yeah, yeah, so when the labs released you'll have at least some test cases with it It's the idea So hopefully they're gonna be the labs are designed to be kind of shorter to the point Hopefully do something useful and actually reinforce what you've learned in the class So The labs will all be in C and assume you are running Linux Some of them you might be able to get away with if you have an M1 Mac They might kind of work but since we're using Linux and we are doing operating system stuff Some stuff might not work ballpark like Probably like for four three to four of the labs will probably work with an M1 Mac. No problem The other ones probably won't first one definitely won't so you have to use a virtual machine or docker or If you want to use local development or use a links machine from the University So they'll all be in C So if you don't know C the C programming language book is a good book to know and we'll have some C examples this class just to make sure that You kind of know what code to expect in this course So please provide some feedback. I want you to get the most of this course this is a really really foundational and important course and It will be important to you if you write software Period so if you write any types of software this course will make you a better software developer and I guarantee you About that so if there's anything you like dislike or want to see more of something Just let me know we have a few lectures of slack. Yeah Some maybe others know So the question is are the labs gonna be based on the previous labs and the answer that is Probably not really because Yeah, some of them were a bit out there like the so who here has Learned about hash tables before hands up who we who here has implemented a hash table. Oh Hey, okay, that's pretty good. So for example, the lab one last Semester was one of the parts was implemented a hash table as like the warm-up lab and The other and there's incoming students. It was not covered in the data data structures course So they had to learn it completely cold and some of them took like 40 hours while you guys would have already done it and That's it's kind of an easy thing to do. You probably would just like copied your code over but Yeah, so this all of the labs are going to be, you know Hopefully to the point and useful is my is my goal So let's start with an overview of the course and this is a quote that I like that is Ridiculously true that all problems in computer science and computer engineering can be solved with another layer of Indirection and guess what an an operating system is just another layer of indirection so all a operating system does as it sits between applications and hardware and its primary goal is to kind of manage and coordinate resources and otherwise get out of your way and One of the like other Really important things is if you want to be good at something in software, you should understand the thing below it So if you are writing software or writing applications Well, the thing below your applications that interacts with the actual the four-day ratchets the hardware goes through the operating system so if you know about the operating system you will be a better programmer and Unfortunately, if you want to be better at operating systems while the layer below that is hardware So you should probably learn about more about hardware but in this course will be learning specifically about operating systems and Generally will be testing your knowledge with more application stuff on top of the operating system instead of going Below and going to hardware although we'll see we might have some assembly pop up, you know here and there So yeah, how many of you have done assembly? There's some luck Did how many of you did you do arm assembly? Yes Okay, so No What is that? What'd you do? What? Nios two Okay, some of you did some like really weird assembly. There's not gonna be that much assembly So if you did arm any code examples will actually I'm transitioning to using something called risk 5 Which is just like an open source arm that you could actually implement a CPU and if you really wanted to but I'll do most Of my examples using that but they'll be really minimal. Otherwise. We're pretty much in C land the whole time So the first question you might want to ask is well What is an operating system and that's actually a fairly complicated question because there's actually no good definition so Ubuntu and Android most people would probably consider different operating systems But if you actually have some knowledge of the internals of an operating system You know that they both use the same kernel Which is kind of a core part of the operating system that we'll be diving into in this course So they use the same core part that is like 90% of it But otherwise you'd consider them, you know completely different operating systems so There isn't really a clear line You might consider those two things the same operating systems if you were just you know Writing command line Utilities or something like that because both your Android phone if you were sadistic enough to actually execute command line Things it could do it the same as you know a server But generally if I'm using an Android phone I'm not going to just start executing stuff from my command line on my phone But if you want to you could and if that was your definition of your application Then they might actually be the same operating system But most people actually like seeing graphics and are a bit more sane and would probably consider them different operating systems so if you care about Desktop applications, maybe that's your application. So maybe you consider them different Operating systems because the way they display graphics is actually different. So for Android that uses something called surface flinger as a library that actually shows you graphics on your screen while if you're using Linux it's using something called at least more modernly called Wayland and If you've never dived into the internals, you probably don't know these names But there are two different display servers to actually show you graphics to your screen and since they're different There's different ways of using them. So you might consider them different operating systems if that's what you care about Okay, so the primary goal of operating systems is to allow you to run more than one application because you know if you actually tried to Program on a CPU with no software. Well CPUs are actually quite the dumb things They just start executing at a fixed address and whatever code you put there is whatever it executes So without an operating system, okay if that's what happens and I just put my application that fixed address and then it starts running and I'm all good So that actually works if you are only running one thing on your hardware So if you're doing a embedded development, which isn't this course, that's perfectly fine You don't need an operating system learn assembly learn see carry on with your life But if you have an operating system, well the idea behind that is well Let's use that fixed address and then it can go to an operating system and that operating system can start as many programs as it wants So there's a little bit more to it on a real system instead of just hey Give me an operating system. It actually points to something that loads the operating system before it boots But we also won't get into that in this course because bootings kind of boring So if you do that You only have one application instead We put an operating system there and then we let it run multiple applications So our operating system is going to have abstractions Everyone has used this abstraction even though you might not have realized what it was called before and the first abstraction is a process and just so you know abstraction is just you know a Generalization just to make our lives a lot easier. So a process basically abstracts a CPU. So it's just a Well extracts Abstracts a running program So each process contains its own set of registers including the program counter, which if we've done assembly we all know about the program counter and Then when this process starts One of the things it does is as part of the information in the in your program Even though you haven't written it it there's actually an address that tells where the CPU should start executing Everyone's you see right? I hope if you've taken this course so There's a bit of magic whenever you start your running your program Contrary to what you think it does not begin at main and we'll see that during this course But there's some special things that go on and we'll kind of break it down and see what actually happens, but You know your code starting to execute at main It's just a nice happy little lie that we tell you to make your life a bit easier before you take this course And we you know we destroy you so get ready for that So I'm just kidding that this course is actually pretty good. It's actually interesting to break it open see what actually goes on So if you're the operating system what you have to do is you have to keep track of registers for all your processes you have to be able to switch between running processes and Since the operating system controls everything you actually get to pick what runs So if you do this poorly your system it might look unresponsive even though there's actually nothing wrong with it So it's a really important thing to do and then you also have to decide When to switch and what to switch to so those are kind of big engineering trade-offs There's no perfect answer to that, but we'll see different algorithms You can do to accomplish that and see what actually goes on So next is talking about memory. So Let's assume that we just have a system with like 16 gigs of RAM and We didn't have an operating system. Well, we could ahead of time Just divide the RAM into like some sections.  So we'll give you eight gigs so you could like go ahead and Set this as a fixed memory thing You're like set this as your memory layout for your physical memory ahead of time But this is really really really inflexible because if LibreOffice Hey if Firefox isn't even open well LibreOffice can't use more than four gigs of RAM because Firefox could open So it needs to leave that space open and if LibreOffice, you know went up here and started You know writing into this RAM then oh no it might overwrite something with Firefox and then you just have a whole mess and then this gets even worse and worse if You want to run multiple applications, right? So if you have your program you need a space in memory and then you don't even know how many programs You might run ahead of time. So this just seems like a really really terrible idea that isn't very flexible So the concept of virtualization is one of the fundamental things of this course and it basically Fools something into thinking it has all the resources So we'll get into it kind of midway through the course But there is virtual memory so each process thinks it has access to all of the memory on your machine And it is the operating systems job to maintain that lie So both LibreOffice and Firefox Could actually start executing at the same virtual memory address So it looks like the same memory address But in the Firefox process it's Firefox's code and in the LibreOffice process It's LibreOffice's code, but it is the same address if you were to like, you know print out the address of main Assuming it starts there. It would be the same address for both them, but they both contain different things So we'll get into that like kind of midway through the course, but this virtualization concept doesn't end up memory You can have virtual machines And so on and so forth. So you can just virtualize this all the way to the machine instead of just memory So this is kind of what I said about virtual memory each process believes it has access to everything and Different processes can have the same starting address with different contents So if you're the operating system, you have to map be able to map virtual memory to physical memory And we'll see this when we get to that then you have to keep track of memory usages like allocations and Deallocations and then you actually have to happen Handle out of memory scenarios So each process thinks it has access to all the memory, but your system has a finite amount of memory So if all the processes use all the memory then it goes out of memory and you have to do something about it spoiler alert the easiest thing to do is just to kill the thing with the Highest RAM usage and then hey it frees your memory. So that's kind of one of the things you can look forward to So powerful concept Processes kind of implement virtual CPU with a set of registers There's virtual memory and then like I said before there's virtual machines as well. So that virtualizes a You know a whole operating system running on computer instead of just one-to-one You can have one physical machine running multiple virtual machines and then the next topic is going to be concurrency and this is typically where People have the most amount of trouble with this course because So far has it wait first thought has anyone ever used threads before? Okay, so some people have used threads before a bit So you will actually get very familiar with threads because Some of you have this nice thing where hey I start executing at main and it keeps on going and everything happens in order and it's all nice Well that illusion is now dead because you'll have multiple things running in the same process at the same time And you have to manage all of it and it can lead to very very hard to debug Things so like even in the Linux kernel there have been bugs that have survived Seven nine years before anyone actually found them because they don't happen all the time And it might take several generations of hardware to even discover the bug So those are the type of things you have to look forward to so You also want the operating system also has to handle this Just at a base level because we have multiple applications running at once especially if you have a multi-core CPU which everyone does by now and you also want Applications to do multiple things at once which you might not have experience with yet But you will get there and that is a way to actually Utilize all of your hardware and use all of your CPU resources which again Doing this and maximizing this will make you a much better programmer So we don't want applications completely isolated from each other either We want them to be able to communicate in some way because an application that doesn't communicate at all Just kind of heats up your Computer heats up the air and doesn't do anything useful because even your first hello world application That does some communication and prints out hello world do something So you want applications to be able to communicate and we'll see that So of course running one application at a time isn't a great experience Sorry, there's a question Are the memories virtual address or physical so the memory you've been dealing with so far Whenever you run anything and you print the address of something it has all been virtual addresses so far And you have not known the wiser so everything you've dealt with is virtual memory even though you didn't know it yet so well, we will figure out that lie and actually Knowing that will make some concepts, you know much much easier So Operating system has to allow multiple Executions at once and actually do it safely and we'll get into some reasons why or how you would actually do that And you have to manage abstractions for different kinds of inter process communication So that's just a fancy word of saying two processes need to talk to each other somehow So even if you print hello world something ran your program and then got the information from it So there is a communication between two programs even though you only wrote one of them And that is called IPC or inter process communication And then of course if you can communicate you actually need to make sure that things only communicate with things they should be communicating with and That will involve permission checking access control things like that that we'll see And then finally we need some persistence So persistence is just data that's accessible between boots and the main thing you have for that is a Hard drive which has a file system on it So a file system just specifies how to organize data on a storage medium which is typically just flash memory for most people and the operating system just has to store and retrieve data and also ensure the integrity of it because if you Wrote your meme to your hard drive. You want to be able to access it later without it being corrupted. So you can enjoy it later, right? so Another the first abstraction that you've all used before even though you might not have realized it is a file descriptor and They abstract both communication and persistence So what they generalize is just anything that can be written to or read from So file descriptor, it's just a number So just some number that you don't know what it represents and you say I want to write some bytes there Or I want to read some rights from whatever that represents and the abstract is you don't have to know what it actually represents it's just a number and You if you write to it it writes to whatever that represents so The operating system has to deal with managing to actually writing those bytes to whatever it represents being it might be a file It might be you know another Application listing it might be your web browser Doesn't matter. They're all going to use this kind of interface and everything's represented by a file descriptor So it could represent a file or you know network connection, whatever So this is to give you a little taste of what to expect in this course So if you have logged on to the Git lab server, let's see. Oh No, there we go. See I had something prepared just in case But I probably should use it. Okay, so if you log into the Git lab thing, it will look somewhat like this Although you won't you'll see about half of these so there'll be some examples So I'll post all of the code examples there so you can run them play with them break them at your will and then the materials You probably won't care about that. That's like the actual source code to the slides But you'll generally probably just want the examples one so in here already There is this 01 overview that will have the code will get into so This is an example of kind of the code will be looking at oh God, can anyone read that like midway? Probably not a put your hands up if you can't actually read that Okay, so like the first three rows cool That better All right. Yeah, hands up if you can read it Yeah All right more thumbs up. Okay. I guess we're here Okay, so This is Just a simple way to open a file So if you haven't written C before if this doesn't make any sense to you then you should probably Review C but in here we have main it has arguments So we're gonna check that it has exactly two arguments if it doesn't Will return an error code so we'll be learning what these error codes are It's just a special number that the operating system uses don't worry about if you don't know what that actually is It's but it's just a number and then we will Use a function called open which returns a file descriptor Which is what I just kind of alluded to and all it is is a number we can read and write from so it just opens The first argument which is hopefully a file and opens it as read only and we get a file descriptor back if you actually read the manuals for this so You through the course you will have to read the manual. So of course if you don't know what the functions do That's okay. You get to read it later But open returns a file descriptor if it's successful if and then return some special value if there's an error That we can check for so we check for that. Otherwise. There's no error And then after that we create an array of four bytes and Then call this read function which takes a file descriptor and that is reading bytes from something So if I read bytes from a file descriptor and I say I want to read four bytes What the operating system will do? So this is a Function that will see how but it will kind of call the operating system So it gets four bytes back and fills up that buffer So if we go through it here and it returns a number of bytes read So if we go through all the bytes read We can read them byte by byte and actually print them out So what this will do is print out that byte as a normal character if you can actually represent as a character Otherwise it will spit out its hex value and hopefully you know hex values if you don't you will So that's all this does so it prints the first four bytes of a file and If we go ahead and run it So throughout all of this so there's also these instructions on the slide So we use Meason as our build system So the steps will always be like this. So you set up a build directory and it's already set up So it doesn't do anything and then you need to compile your project and tell it where your build directory is and Then goes ahead and builds it. So we made an executable called read for bytes and Read for bytes. Whoops. It is in build So read for bytes just takes a single argument that is a file So I can be a bit meta about it and read the first four bytes of my C file So the first four bytes of my C file. It starts off with an include So the first few bytes of my include file are you know pound INC so that's the first bit of include So with this little tool we get to have some fun with it because you can start poking at a bunch of random things so Everyone's used LS before I hope so I can poke it at LS because it's just a file And I can see what it is.  Well, the first bytes kind of garbage 7f doesn't mean much to you, but the rest of it is ELF hmm interesting you can actually read it and that is not a coincidence and oddly enough if I Browse other files. I don't know you name Huh it also starts with that And also if I go really meta and I See the executable that I'm executing. Well, it's also that Wow, so we'll get into that in the next lecture So then finally most kernel code is going to be device drivers Which is like 80 plus percent of real kernel code like real operating system code Generally, they're really really boring and involves reading a bunch of specifications Realizing they're wrong and trying to do some hacky workarounds about it There's generally inconsistencies between them and it's just a big pain So if you get into this you might be stuck doing this But try and do the fun core work that we'll go into in this course And don't be stuck doing this because you're just reading a bunch of dry tech specs and realizing that they're completely wrong Because if you go and look at some Linux code This is an actual comment in the source code making fun of the QA process between some BIOS you know developers and a BIOS is just Some baseline code your system implement So you can build an operating system on top of it where it does some it stands for basic input Input output system, so I'll do some basic input to output So your operating system has to use it and this is the joke for their QA process Where they're just a bunch of people that just write some code Check if it compiles if it doesn't they just write some more code Soon as it compiles and you can see how old it is it just checks if it boots windows 98 and as soon as it boots Windows 98 doesn't matter what the rest of code works or if it was a fluke or anything They just ship it and that's the code and then it is now your problem to deal with so you can see that Hey, you know When it was first released it was really it was bad And they had to do some really hacky work around and then a month later They actually you know did some QA and actually fix it a bit So it took about a month to fix it But the problem with hardware is as soon as you ship it you can't change it So you actually have to address it in software and work around it and it's quite awful So hopefully you can avoid doing that so as the teaser to the next lecture, so just to give you a Little taste of this course this is actually hello world. So hopefully you can read hex So yeah, oh that was in question. Okay, so hopefully you can read hex so Here This is actually hello world I don't know why people teach you this and see you're like python or something like this This is the shortest hello world. You'll ever see that actually executes. So this is a hundred and sixty-eight bite So each of those is a single bite and believe it or not. This actually works and I will demonstrate it so in here in Yours so it might not actually work for yours So there is a file called hello world Linux a arch 64, which is arm and we can see here that it is a hundred and 68 bytes and if I go and execute it It prints hello world Which is kind of cool? ah clubs, which is really really confusing so Everyone's been told so far like see is low level. It's got no overhead. It's great, right? Okay. Well Whoops, let's see Okay, I'll just write this fast. So let's write the easiest hello world. We'll see so include standard h it main Let's be nice and actually return whoops Let's be nice and return zero So there's my hello source file. I guess it's how big that is by itself So my source file it's 74 bytes pretty good Now if I go ahead and compile it Let's see how low overhead C is any guesses as to how big it is so hands up if it's you know Thousand under thousand They've got a few under two thousand Okay sees pretty good under five thousand Under ten thousand Under twenty thousand Okay under one gigabyte Okay, that's still not everyone's hands up like if people are asleep geez okay, so Given that it like probably around like five to ten thousand So if I look at it my hello world is like 14,000 geez What low overhead of C mines like mine's so much smaller than that and what's it do? Doesn't do anything special of this Prince. Hello world. How's that any different than mine? Yeah, it's fine so Yeah, try that like Javascript or something like that or Python gets way worse so What I'll leave you at is that there's three major concepts in this course So you'll learn how the following applies to operating systems and also figure out that hello world example virtualization concurrency and persistence and just remember I'm pulling for you. We're all in this together