Operating Systems Chapter 5: Input/Output Management Instr: Yusuf Altunel IKU Department of Computer Engineering
Content Principles of I/O hardware Principles of I/O software I/O Devices Device Controllers Direct Memory Access Interrupts Principles of I/O software Programmed I/O Interrupt Driven I/O I/O Using DMA
Introduction OS Functions The I/0 codes represent to control all the computer’s I/O (Input/Output) devices issue commands to the devices catch interrupts handle errors to provide an interface to the devices device independence: the interface should be the same for all devices The I/0 codes represent a significant fraction of the total operating system
I/O Hardware block devices stores information Common block sizes: in fixed-size blocks, each one with its own address. Common block sizes: range from 512 bytes to 32,768 bytes. it is possible to ‘read or write data blocks independently of all the other ones. Disks are the most common block devices
I/O Hardware character devices delivers or accepts a stream of characters, no block structure is available. It is not addressable does not have any seek operation. Examples: printers, network interfaces, mouse, …
Some device, network, and data base rates Speed Some device, network, and data base rates
Device Controllers I/O devices have components: device controller mechanical component electronic component device controller the electronic component can handle multiple devices Controller's tasks convert serial bit stream to block of bytes perform error correction make data available to transfer it to main memory
Memory-Mapped I/O Devices addressed independent of the memory Devices are addressed in common address space A hybrid approach
Bus Architecture (a) A single-bus architecture (b) A dual-bus memory architecture
Direct Memory Access CPU must be able DMA (Direct Memory Access) to address the device controllers to exchange data with them DMA (Direct Memory Access) memory address register The memory address to be used in DMA operation a byte count register The amount of bytes to transfer one or more control registers to identify the I/O port to use the direction of the transfer unit: bytes or words the number of bytes to transfer in one burst
DMA Transfer Operations of DMA Transfer
Interrupts When an I/O device finishes its job interrupts can be it causes an interrupt by asserting a signal on a hits line This signal is detected by the interrupt controller a chip on the main board interrupts can be enabled or disabled by the operating system If no other interrupts are pending process the interrupt immediately. If another one is in progress the device is just ignored for the moment it continues to assert until it is serviced by the CPU Pending: Askıda
How an Interrupt Happens Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires
Handling Interrupts To handle the interrupt, the controller puts a number on the address lines for the address of the device The interrupt signal causes the CPU to stop what it is doing and start doing something else. The number on the address lines is used as an index into a table called the interrupt vector to fetch a new program counter. program counter points to the interrupt service procedure.
I/O Software Device independence Uniform naming Error handling programs can access any I/O devices without specifying device in advance floppy, hard drive, CD-ROM ... Uniform naming device name must be machine-independent Error handling handle erorrs as close to the hardware
I/O Software Synchronous vs. asynchronous transfers Buffering blocked transfers interrupt-driven transfers Buffering data coming from a device cannot be stored in final destination Sharable vs. dedicated devices disks are sharable tape drives can not be shared
I/O Types Programmed I/O Interrupt-driven I/O I/O using DMA
Programmed I/O user process to print string “ABCDEFGH” on the printer: assemble the string in a buffer in user space acquire the printer for writing by making a system call to open it If the printer is currently in use fail and return an error code or will block until the printer is available make the system call to print the string on the printer
Programmed I/O Operating System copies the buffer checks to see to an array in kernel space checks to see if the printer is available If not, it waits until it is available copies the first character to the printer’s data register if the printer is ready to accept another one when ready, it prints the next character
Steps in Printing a String
Interrupt-Driven I/O to allow the CPU In case of system call do something else while waiting for device In case of system call to print the string is made, the buffer is copied to kernel space, as soon as the printer becomes ready the first character is copied to the printer cuncerrently., CPU calls the scheduler to run some other processes The process printing the string is blocked until the entire string has printed.
Example: Writing a string to the printer using interrupt-driven I/O Code executed when print system call is made Interrupt service procedure
I/O Using DMA Interrupts take time A solution is to use DMA wastes CPU time A solution is to use DMA let the DMA controller feed the characters to the printer one at time without bothering the CPU DMA is programmed I/O the DMA controller is doing all the work instead of the main CPU
Disadvantages DMA controller is If then much slower than the main CPU. the DMA controller is not capable of driving the device at full speed or the CPU usually has nothing to do while waiting for the DMA interrupt then interrupt-driven I/O or even programmed I/O may be better
Input/Output Management End of Chapter 5 Input/Output Management