The Input Output System The Input Output System

  • Slides: 14
Download presentation
The Input / Output System • The Input / Output System is one of

The Input / Output System • The Input / Output System is one of the four pillars on which a computer stands; the other being the processor, main memory and the file system. • It is considered to be the least satisfactory member of the quartet because of its slowness and lack of consistency. These characteristics are consequence of nature of I/O devices and their role in trying to provide communication between the microsecond domain of the computers and the more leisurely outside world. • One of the functions of O. S. is to control all the I/O devices. • The range of I/O devices and variability in their nature, speed, design, etc. make it difficult for the O. S. to handle them with any generality.

Characteristics of I / O Devices Characteristic Example Data Rate Disk : > 2

Characteristics of I / O Devices Characteristic Example Data Rate Disk : > 2 MB /S Keyboard: 10 -15 bytes/s Unit of Transfer Disk: 1 Block (0. 5 K, 1 K, 2 K, . . ) Screen: Single Character Operations Disk: Seek, Search, read, write, . . Printer: Write, move paper, . . Error Condition Disk: read Error, . . Printer: Paper out, . . The O. S. must: • Issue commands • Catch interrupts and handle errors • Provide an interface between devices and rest of the system Note: Computer communicates with I/O devices through I/O bus system.

I / O Devices (cont) • In our study, we are concerned with programming

I / O Devices (cont) • In our study, we are concerned with programming the I/O devices not with designing, building and maintaining them. • Our interest will be restricted to how the hardware is programmed and not with how it works inside. • But programming the I/O devices is concerned with their internal structure and operation. • I/O devices have been designed to be used in a range of computer systems; e. g. the same laser printer can be used on DOS, windows and Unix operating systems.

Categories of I / O Devices 1. Block Devices • A block device stores

Categories of I / O Devices 1. Block Devices • A block device stores data in fixed size blocks each with its own address. The block size may be 0. 5 K, 1 K, 2 K, … • Each block can be read and written independently of all the other blocks. • The block devices include magnetic, optical and other forms of secondary storage devices; e. g. disks, etc. • These are inherently complex and require more extensive services from the O. S. to deal with random access to data, error checking, bi-directional flow of data. 2. Character Devices • Data is transmitted as streams of characters; e. g. keyboard.

Device Controllers (cont)

Device Controllers (cont)

Device Controllers (cont) • The interface between the DC and the device is often

Device Controllers (cont) • The interface between the DC and the device is often a very low level. • Example, consider a disk formatted with 8 sectors of 512 bytes per track. – What actually comes off the drive into the buffer of the DC is a serial bit stream starting with a preamble* then the 4096 bits in a sector and finally a checksum or error correcting code (ECC). – The DC converts the serial bit stream into a block of bytes and perform the necessary error correction. – DC then generates an interrupt to tell the CPU that data is ready for transfer. – THE CPU then copies this data from the buffer of the DC into the RAM. * The preamble is written when the disk is formatted and contains the cylinder and sector number, the sector size and similar data.

DC (contd. ) • Each device controller has a few registers; these are used

DC (contd. ) • Each device controller has a few registers; these are used for communication with the CPU. • The CPU gets the results and device status by reading one or more bytes of information from the registers of the DC. • The O. S performs I/O by writing commands into the registers of the DC. The IBM PC floppy disk controller, for example, accepts 15 different commands, such as READ, WRITE, FORMAT, … • Many of these commands have parameters which are also loaded into the registers of the DC. • When a command has been accepted the CPU leaves the controller alone and goes off to do other work. • When the command has been completed the controller causes an interrupt form the controller registers informing the CPU that command has completed.

Direct Memory Access (DMA) Many device controllers, especially those for block devices support direct

Direct Memory Access (DMA) Many device controllers, especially those for block devices support direct memory access (DMA). To explain DMA, let us first look at how the disk reads occur when DMA is not used: 1. The DC reads a block (one or more sectors) from the drive serially, bit by bit and stores it in its own (DC’s) internal buffer. 2. It performs checksum computation to verify that no read errors have occurred. 3. The DC causes an interrupt to tell the CPU that data in its buffer is ready to be transferred to the main memory. 4. The CPU reads the block from the buffer of the DC into the main memory a byte or a word at a time by executing a loop. (This involvement of the CPU in transferring data from the buffer of the DC into the RAM is considered to be the wastage of the CPU time)

DMA (cont) • To liberate the CPU from the task of transferring data between

DMA (cont) • To liberate the CPU from the task of transferring data between the device and the main memory explicitly, the DMA was invented. • This is accomplished by permitting the device controller to access the memory directly. • When DMA is used: • The CPU passes the following to the controller: 1. The disk address of the block 2. Memory address A, say, where the block is to go 3. No. of bytes n, say to be transferred. • The CPU then continues executing the next instruction. • The controller then: • o reads the entire block from the device into its buffer o verifies that data has been read correctly by applying the checksum, o copies the first byte or word into the main memory at the address A, increments A and decrements n. This process is repeated until n becomes zero. o causes an interrupt. When the O. S gets control of the CPU it does not have to copy the block to

DMA (cont) • Q. 1. Why does the DC need an internal buffer? •

DMA (cont) • Q. 1. Why does the DC need an internal buffer? • Q. 2. Why does the DC not transfer data directly into the main memory as soon as it gets from the disk?

I/O Software (Key concepts / Objectives) 1. 2. 3. Device independence It should be

I/O Software (Key concepts / Objectives) 1. 2. 3. Device independence It should be possible to – write programs that can be used with files on floppy disk, hard disk, CD, . . without modifying them for each device type. – Open, save … files in a similar manner on devices of all types. O. S. should take care of the fact that devices are really different and different software required to handle them. Uniform naming The name of a file or a device should be string or integer and should not depend on the device in any way. Error handling – Errors should be handled as close to the hardware as possible. – If a device controller discovers a read error it should try to correct the error itself if it can. Otherwise device driver should handle it by trying to read the block again. – Many errors are transient; i. e. read errors caused by the specks of dust on the read head and will go away if the operation is repeated. – If lower level layers cannot fix the problem only then the upper layers be told.

I/O Software (Key concepts / Objectives) 4. Sharable versus Dedicated – – – 5.

I/O Software (Key concepts / Objectives) 4. Sharable versus Dedicated – – – 5. Some I/O devices such as disks are sharable. Multiple users can open files on the same disk at the same time. Other devices such as printers are dedicated to a single user until that user is finished. These devices are confronted with the problems such as deadlock. The O. S. must handle both shared and dedicated devices to avoid problems. Efficiency Perhaps the most significant characteristic of the I/O system is the disparity in speed between the I/O devices and the processor & memory. Due to mechanical movement the I/O devices can not compete the nano-second speed of the processor & memory. It is important to operate them at maximum efficiency.

Device Drivers A device driver: • is a software module which manages the communication

Device Drivers A device driver: • is a software module which manages the communication with, and the control of a specific I/O device or type of device. • contains all the device department code. • convert an abstract request from the device independent S/W above it into specific commands directed to the device itself; e. g. a typical request is to write a record to a floppy disk. – This would be concerted by the device driver into a series of actions such as checking for the presence of disk in the drive, locating the file, positioning the head etc. in short it must determine which controller operations one required and in what sequence. – Once it has determined which commands to issue to the controller, it starts issuing them by writing into the controller’s device registers. Some controllers can handle only one command at a time. Other controllers accept a linked list of commands which they carry out without any help from the O. S.

Device Drivers (cont) • After the commands have been issued one of the two

Device Drivers (cont) • After the commands have been issued one of the two situations may apply. 1. The device driver must wait until the controller does some work for it, so it blocks itself until an interrupt comes in to unblock it. 2. Operation finishes without delay, so the driver need not block. As an example scrolling the screen on some terminals (including IBM PC) requires just writing a few bytes into the controller’s registers. No mechanical motion is needed, so the entire operation can be completed in a few microseconds. Term paper: What are device drivers? Explain their working.