1 / 70

INPUT/OUTPUT

INPUT/OUTPUT. Operating system controls all I/O devices Two aspects of I/O devices are important for operating system: I/O hardware I/O software. Principles of I/O Hardware. I/O devices Block Devices: stores information in fixed-size blocks: Disk (seek operation)

Download Presentation

INPUT/OUTPUT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INPUT/OUTPUT • Operating system controls all I/O devices Two aspects of I/O devices are important for operating system: • I/O hardware • I/O software

  2. Principles of I/O Hardware I/O devices Block Devices: stores information in fixed-size blocks: Disk (seek operation) Character Devices: Delivers or accept a stream of characters, without regards to any block structure: Printer, network interfaces,… Data rates of some common devices are presented in the next slide

  3. Device controllers • I/O units consist of mechanical and electronic component (electronic component called device controller or adapter) • O.S initialize the controller with few parameters and controller take care of the rest. For example if a disk formatted with 256 sectors of 512 bytes a serial bit stream of 4096 bits with all necessary information is come off the drive. Controller assembles the bits and changes the bits into the bytes and send them to main memory

  4. Device controllers

  5. Device controllers

  6. Memory-Mapped I/O • Each controller has few register and maybe a data buffer (e.g. video RAM) to be able to communicate with CPU • CPU communicates with the control registers and data buffer in three ways: 1- With assigned I/O port of that device: IN R0,4 reads the contents of port 4 MOV R0,4 reads the contents of memory word 4 and put it in R0.

  7. Memory-Mapped I/O 2- Memory-mapped I/O: means the registers are part of the memory address (b in the previous slide) 3- Hybrid scheme: It has memory-mapped I/O data buffers and separate I/O ports for control registers In all of these cases the communication with CPU is through the buses

  8. Memory-Mapped I/O Disadvantage of Separate I/O and memory space: • In C/C++ we don’t have IN or OUT commands to read the ports Some of the advantages of Memory-mapped I/O: • The device driver can be written entirely in C/C++ • Every instructions that can reference memory can also reference control registers

  9. Communication with I/O Devices • If there is only one address bus all the I/O devices and memory modules can check memory references by examining this bus (see a in the next slide) • But most of the systems has a dedicated high-speed memory bus for optimizing memory performance (see b in the next slide). The problem with this design for memory-mapped I/O is: I/O devices have no way of seeing memory addresses because they go by on the memory bus.

  10. Communication with I/O Devices

  11. Communication with I/O Devices • One possible solution for the system with multiple buses is to first sending all memory references to the memory. If the memory fails to respond , then CPU tries other buses. • Pentium solves this problem by filtering addresses in the PCI bridge chip. This chip checks the range of memory address references, if it finds non-memory references, it forwards them onto PCI (Peripheral Component Interconnect) bus instead of memory bus (see next slide)

  12. Direct Memory Access (DMA) • Instead of using CPU for exchanging data with different controllers DMA is often used. • DMA has access to the system bus independent of CPU and it can be programmed by the CPU to exchange data (next slide shows how DMA works).

  13. Principles of I/O Software Goals of the I/O software 1- Device independence: It should be possible to write programs that can access any I/O device without having to specify the device in advanced. For example sort<input>output should work for floppy disk , IDE or SCSI disk

  14. Principles of I/O Software 2- Uniform naming: The name of the device should be simply an string or a integer that is not depending on the device. For example by mounting, each device can be addressed by file path name 3- Error handling: Error should be handled close to the hardware

  15. Principles of I/O Software 4-Syncrhronous(blocking) vs. asynchronous (interrupt-driven) transfer. Most physical I/O are asynchronous but users program can be written much easier if they write with blocking I/O operations 5- Buffering, shareable and dedicated devices.

  16. Principles of I/O Software • Goals of the I/O software can be achieved by structuring the software in following layers:

  17. Interrupt Handler • The device driver blocks when it performs I/O operation. • When I/O completes, the controller issues interrupt and interrupt handler runs interrupt service procedure • Finally interrupt handler unblocks the driver, therefore its role is hiding the I/O controller interrupts.

  18. Device Drivers • The device drivers command the controllers by setting controller registers • The device driver for each controller is created by device’s manufacturer and should be put into the kernel • O.S. should have an architecture to allow the installation of different device drivers. Device drivers usually positioned below the rest of O.S. (see the next slide)

  19. Device Drivers • The most important function of device driver is changing abstract read/write request issued by device-independent software above it to concrete form. • For example a disk driver converts a linear block number into head, track, sector and cylinder of the related disk. • Device driver can queue the requests and report the errors to their callers.

  20. Device-Independent I/O Software • Driver contains device dependent codes. Some other functions that are common to all devices and can be used as the interface to the user-level software are in the device-independent software • The basic functions of the device-independent I/O software are presented in the next slide

  21. Device-Independent I/O Software

  22. Uniform Interfacing for Device Drivers • It means O.S. should have common functions such as naming and protection for different drivers. • For example in Unix the name of /dev/disk0 can be mapped to locate any driver. It contains the i-node that contained the address of that device. • Also both Unix and Windows have the protection method that can be used for all devices uniformly.

  23. Without standard driver interface With standard driver interface

  24. Device-Independent I/O Software • Buffering can be used both in the user space and kernel space. With buffering O.S. stores the data from devices that have different speed (see next slide) • Error Reporting: The general errors (not device dependent errors) is handled by O.S. For example reading or writing the wrong device

  25. Buffering

  26. Device-Independent I/O Software • Allocating and Releasing dedicated devices is done by O.S. For example O.S. does not allow acquiring a device that is not available. Also O.S. keeps a queue of the processes that are requested the same device • Device-independent software provide a unique block size (from different disks with different sector sizes) to the higher layer.

  27. User-Space I/O software • The collection of library procedures such as count = write( fd, buffer, nbytes) scanf, printf commands • Spooling. For example spool printer. Process first put the file in spool directory and daemon (the only process having permission to the printer) print the file in the directory.

  28. Summary of I/O System

  29. Disks • A groups of magnetic disks organized into cylinders is the example of I/O devices • The IDE (Integrated Drive Electronics) disks have sophisticated drives contains microcontrollers for doing some of the work of the real disk controller • Disk controllers may do multiple seeks (i.e., overlapped seeks) on drives • Next slide compares an early floppy disk with a modern hard disk

  30. Disks • On older disks the number of sector per track was the same for all cylinders • Modern disks are divided into zones with more sectors on the outer zones than inner zones (see the next slide) • To hide the details of how many sectors each track has, most modern disks presents a virtual geometry to the O.S. (see next slide)

  31. Virtual geometry Disk with two zones

  32. Disks • The software acts as there are x cylinders, y heads and z sectors per track. • Controller remaps a request for (x,y,z) onto real cylinder, head and sector • The max value for Pentium is (65535, 16 and 63) means max capacity of disk with 512 bytes per sector is 31.5 GB • To get around this limit logical block addressing, in which disk sectors are just numbered consecutively starting at 0, is used

  33. Disk Formatting • Before the disk can be used, each plotter must receive a low-level format done by software. It means tracks contain some number of sectors with following format • The start of each sector is recognized by hardware by a certain bit pattern (named preamble) and ECC contains information that can be used for recovery

  34. Disk Formatting • After low level format each sector in the track is identified by a number. • Cylinder skew means offsetting the position 0 of each track from the previous track to improve the performance (see next slide). It is done to allow the disk to read multiple tracks in one continuous operation without loosing data

  35. Disk Formatting • Reading the sectors continuously requires a large buffer in the controller • But if controller has a buffer just for one sector and wants to read to consecutive sectors, after reading the first one, its data must transfer to memory. While controller transfers the first sector, the next sector will be passing under the disk head and controller can not buffer its arriving bits. • This problem can be solved by numbering the sectors in an interleaved fashion when formatting the disk. See next slide

  36. No interleaving Single interleaving Double interleaving

  37. Disk Formatting • After low-level format the disk is partitioned • On Pentium sector 0 contains the partition table • Finally high-level format prepare a disk for use by formatting each partition separately. It means storage administration (free list or bit map), root directory, empty file system and etc. are created for each partition

  38. Disk Arm Scheduling Algorithm • For most disks, the seek time delay dominates the other two delays (rotational and data transfer delay) so the lower layers of O.S. ( for example device driver or even controller if it accepts multiple requests) try to reduce the disk seek time • Many disk drivers maintain a table, indexed by cylinder number, with all the pending requests for each cylinder • By using this structure following algorithms can be used for serving the requests

  39. FCFS • If disk driver accepts request as First Come First Served (FCFS) little can be done to optimize disk seek time • For example suppose while seek to cylinder 11 is in progress, new requests come for 1,36,16,34, 9 and 12. FCFS requires total arm motion of 111 cylinders

  40. Shortest Seek First (SSF) • Always handles the closet request next, to minimize the disk seek time • Its performance is better than FCFS but the problem is the requests far from the middle may get poor service (not a fair algorithm) • As previous example current request is for cylinder 11 and requests come for 1,36,16,34, 9 and 12. SSF requires total arm motion of 61 cylinders

  41. Elevator Algorithm • Head keeps moving in the same direction (same as elevators) until there are no more outstanding requests in that direction, then head switches the direction (it is also called SCAN algorithm) • Same Example: Current request is for cylinder 11 and requests come for 1,36,16,34, 9 and 12. Elevator algorithm requires total arm motion of 60 cylinders

  42. Elevator Algorithm • Software should maintain 1 bit to know the direction. Elevator also should know whether it is going UP or DOWN • Elevator algorithm is usually worse than SSF but for previous example it is slightly better

  43. Deadlock • In the Multiprogramming environment processes compete for the resources • Resources can be preemptable resource that means it can be taken away from the process owning it with no ill effects (such as memory) • A nonpreemptable resource is the one that cannot be taken away from its current owner without causing the computation to fail

More Related