In the last lecture, we have studied about storage structure under the basics of operating system. And in this lecture, we will be studying about input output structure which also comes under the basics of operating system. So, as we studied about storage structure in the previous lecture, we see here that storage is only one of the many types of input output devices within a computer.
So, what are input output devices? Input output devices are the devices that are used for either giving input or getting output from your computer. And storage also is just one of the many types of input output devices that we have.
So, we see that input output devices are something that is very important. So, a large portion of operating system code is dedicated to managing I O both because of its importance to the reliability and performance of a system. and because of the varying nature of the devices. So, as I told you, since input output devices and managing input output is very important.
So, when you code the operating system, a very large portion of that code is dedicated for managing the input output. And why is that? It is because of its importance to the reliability and performance of the system.
The reliability and performance of a system greatly depends upon how its input and output are managed. And also because of the varying nature of the devices. We know that we have different input output devices and then all these input output devices are very different in nature. So, since they are very different or varying in nature and because it is very important for the reliability and performance of a system, a large portion of operating system code is dedicated for managing this input output. So, we see that a general purpose computer system consists of CPUs and multiple device controllers that are connected through a common bus.
Now, this was something that we have studied when I started teaching about operating system. Let's just go back and look into it once more. So, here when we studied about computer system operation, we said that a general purpose computer contains one or more CPUs and a number of device controllers connected through a common bus.
that provides access to shared memory. So, here we see that we are having different devices and each devices they are connected to a particular device controllers like this. Here we see that the disks are connected to the disk controllers and then the USB devices like your mouse, keyboard and printers were connected to the USB controllers and monitor is connected to the video adapter. So, each device is connected to a device controller which are connected via a common bus.
This line here represents the common bus and they provide access to shared memory. So, that is what we have said over here. And now, each device controller is in charge of a specific type of device. We know that there are different types of device and each device controller is in charge of a specific type of device.
And this device controller, it maintains two things. What are they? One is a local buffer storage. and the other one is a set of special purpose registers.
So, we will see why it maintains this and what is the use of this as we proceed further. But remember that a device controller maintains a local buffer storage and a set of special purpose registers. And typically operating systems have a device driver for each device controller.
Now we have talked about device controller. Now we are talking about another term called device driver. Now, operating systems have a device driver as well for each device controller.
Let's see why do we have that. This device driver understands the device controller and presents a uniform interface to the device to the rest of the operating system. So, as I told you, each devices are very different.
They have a varying nature as we said. And then each device controller also will be different. for different devices.
And then how will these device controllers interact with the operating system? We need a proper interface that allows these device controllers to interact to the operating system. So, these device drivers, they understand what kind of nature does the device controller have.
And it provides a uniform interface to the device to the rest of the operating system. So, that is the function of your device driver. Now let us see How does a basic I O operation work?
So, here we will be seeing the working of an I O operation. So, here we have a diagram and here is the explanation of that. So, let us see.
First of all, To start an I O operation, the device driver loads the appropriate registers within the device controller. So, when an I O operation has to be performed by any device, so what it does, the respective device driver of that device, it loads the appropriate registers within the device controller. So, when we were talking about device controller, I told you that Device controller maintains a set of registers.
So, from these registers, the appropriate registers that are required for performing that particular input-output operation will be loaded by the device driver. And then the second point is, the device controller in turn examines the contents of these registers to determine what action to take. Now, why does it load those appropriate registers? Those registers are loaded because In that registers we have the information or the data about what is the action or what is the exact input output operation that has to be performed.
So, after the device driver loads those appropriate registers within the device controller, the device controller will examine the contents of those registers and determine what action to take. So, as I said these registers will contain the information about what action to take. So, the device controller will examine that in order to know what is the action that has to be taken. And then the controller starts the transfer of data from the device to its local buffer. So, whatever has to be performed, the data for that will be transferred to the local buffer of the device controller.
So, when I talked about device controller, I told you it has a local buffer and a set of registers. So, we saw what the registers are used for. And now, comes the local buffer.
So, the data from the device is transferred to the local buffer of the device controller. And then, once the transfer of data is complete, the device controller informs the device driver via an interrupt that it has finished the operation. So, we saw that the data was transferred to the local buffer.
And then, once the data transfer is complete, once the execution is complete, Then the device controller will inform the device driver that it has finished its operation. So, once operation is finished, the device controller will inform the device driver. And how will it inform? It will inform via an interrupt.
So, I have already explained in one of the previous lecture about interrupt. So, via an interrupt it will be informed to the device driver by the device controller that it has finished its operation when it is done. And then what happens? the device driver then returns control to the operating system.
And after it is done, the device driver will return the control to the operating system. So that it can continue with the other work or task that it has to do. Now this is the diagram that represents whatever I was explaining over here. Here you have the CPU and here we have a device.
And this is the memory. And then when the device has an input output request, after loading the registers and everything, The device controller loads its data to the local buffer. And then it goes via the CPU to the memory.
So here we have the instruction execution cycle and the data movement between the CPU and the memory. And whatever task has to be done will be done. And then the data that has been transferred back to the device will be transferred back.
And then once everything is done via an interrupt it tells that I am done with my operation. So, this is the diagrammatic representation of whatever is written here. Now we see that there is a disadvantage to this kind of operation.
Let's see what it is. This form of interrupt driven I O is fine for moving small amount of data but can produce high overhead when used for bulk data movement. So, we see that when this kind of a system is used, it is okay when it is used for moving small amount of data. But if you want to move or if you want to do input output operations that involve large or bulk amount of data movement, then this is not a very efficient system.
Why? Because it is going to take up so much of your CPU and time. Because the CPU is always being interrupted over here. And in order to solve that, what do we do? To solve this problem, Direct Memory Access also known as DMA is used.
So in order to solve this problem, we have something called Direct Memory Access called DMA. So, that one is used. So, that is what we represent over here.
And let's see what happens in DMA. After setting up buffers, pointers and counters for the I O devices, the device controller transfers an entire block of data directly to or from its own buffer storage to memory with no intervention by the CPU. So, even in this direct memory access, the first three points remain the same.
Okay? They will have to load the registers, buffers and everything. And after doing that, instead of going via the CPU in this way, what it does is that the device controller, it transfers an entire block of data directly to the memory from its own buffer storage without intervention of the CPU.
So, in DMA, we see that the CPU is not affected. It just goes directly to the memory. So, whatever has to be sent to the memory can be directly sent.
And whatever has to be taken back from the memory also can be directly done without intervention of the CPU. So, this is direct memory access. So, in this direct memory access, only one interrupt is generated per block to tell the device driver that the operation has completed. So, here only one interrupt per block is required. But in case of our Other system that we first explained, there will be interrupt per byte of data that is being transferred.
So, the CPU is interrupted so many times making it an inefficient system. But here only one interrupt is generated per block. And when is it generated? It is generated to tell the device driver that the operation is completed.
When it is completed, it is generated just to tell the driver that the operation is completed. So, while the device controller is performing these operations, The CPU is available to accomplish other works. So, this is one of the greatest advantages of this.
As we said, in DMA, CPU is not intervened. So, even when this I-O operation is occurring, the CPU is free to perform its other task and it will not be disturbed. So, this is the advantage of direct memory access.
So, that is how input-output operation works and how DMA works. I hope this was clear to you. This was about the input-output structure which is also the basics of your operating system. So, I hope this was clear to you. Thank you for watching and see you in the next one.