Chapter 5.pptx

49
CHAPTER FIVE 1 INPUT/OUTPUT I/O devices I/O software Organization of I/O functions Disk scheduling Clocks

Transcript of Chapter 5.pptx

PowerPoint Presentation

CHAPTER FIVE1INPUT/OUTPUT I/O devices I/O software Organization of I/O functions Disk scheduling Clocks1I/O Devices2Main functions of an operating system with regard to I/Ocontrol all the computers I/O (Input/Output) devicesissue commands to the devicescatch interruptshandle errors provide an interface between the devices and the rest of the system that is simple and easy to use ProcessInputOutput2I/O devices ..3External devices that engage in I/O with computer systems can be roughly grouped into three categories:Human readable: Suitable for communicating with the computer user. Examples include video display terminals, consisting of display, keyboard, mouse, and printers.Machine readable: Suitable for communicating with electronic equipment. Examples are disk and tape drives, sensors, controller, and actuators.Communication: Suitable for communicating with remote devices. Examples are digital line drivers and modems3The following are the differences between I/O Devices 41.Data rate:- data rates vary b/n I/O devices .Out of all devices keyboard is the least data transmission rate and graphics display is the highest transmission rate.2. Application:-Different devices have different use in the system. 3. Complexity of Control:-A disk is much more complex whereas a mouse or a keyboard requires simple control interface. 4. Unit of transfer:-Data may be transferred as a stream of bytes or characters or in larger blocks. 5. Data representation:-Different data encoding schemes are used for different devices. 6. Error Conditions:-The nature of errors differs widely from one device to another.

Cont5I/O devices cover a huge range in speeds

5

Input/output component

6To view a document stored on a hard disk, you accessed hard disk and issue the command to display the documentThis tasks are performed by input-out put hard ware and I/O software in coordination . Input/out put componentI/O hardware are I/O devices such as hard disk, floppy diskIncludes an electrical component called devices controller Consists of mechanical and electrical componentMechanical component is the devices itself Electrical component is the devices controller I/O software Include different layer of the operating system that mange the I/O devices Device Controllers 7Form of a printed circuit card that can be inserted into an expansion slotHas a connector on it, into which a cable leading to the device itself can be plugged The interface between the controller and the device is often a very low-level interface Receive serial bit stream, convert the serial bit stream into a block of bytes and calculate checksumAfter the block declared to be error free, it can then be copied to main memory7I/O hardware8Electrical engineers view of I/O hardwarechips, wires, power supplies, motors, and all the other physical components that make up the hardware Programmers view of I/O hardwarethe interface presented to the softwarethe commands the hardware acceptsthe functions it carries outthe errors that can be reported back 8I/O devices9I/O devices can be roughly divided into two categories: block devices: stores information 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 each block independently of all the other ones. Disks are the most common block devices.character devices:A character device delivers or accepts a stream of characters, without regard to any block structure. It is not addressable and does not have any seek operation. Printers, network interfaces, mice (for pointing), rats (for psychology lab experiments), and most other devices that are not disk-like can be seen as character devices. 9I/O communication 10Each controller has a few registers that are used for communicating with the CPU

control registersUsed to communicate with the CPUOS reads/writes onto this register to command the device to receive or send and check status data bufferA buffer that the operating system can read and writea common way for computers to display pixels on the screen is to have a video RAM, which is a data buffer, available for programs or the operating system to write into

10Memory-Mapped I/O 11

11Cont.12Two alternatives exist for the CPU to communicate with the device controllerAssign I/O port number to each device controllerEach device will have a unique 8-bit or 16-bit integer addressTo access this device OS can use these addressIN REG,PORT - to read control register to CPU REGOUT PORT,REG to write the CPU REG to a control register Memory-mapped I/OEach control register is assigned a unique memory address to which no memory is assigned Memory-Mapped I/O are assigned addresses at the top of the address spaceDevice-control registers are mapped into the address space of the processorCPU executes I/O requests using the standard data-transfer instructions to read/write the device-control registers.

12Cont.13Memory-Mapped I/O are assigned addresses at the top of the address spaceDevice-control registers are mapped into the address space of the processorCPU executes I/O requests using the standard data-transfer instructions to read/write the device-control registers.E.g. Graphics controller has a large memory-mapped region to hold screen contents sending output to screen by writing data into the memory-mapped region. Controller generates the screen image based on the contents of this memory.Simpler and faster to write millions of bytes to the graphics memory compared to issuing millions of I/O instructions.13Memory-Mapped I/O 14Advantages:device control registers are just variables in memory and can be addressed in C the same way as any other variablesDoesnt require the use of assembly code like IN or OUTI/O device driver can be written entirely in Cno special protection mechanism is needed to keep user processes from performing I/O every instruction that can reference memory can also reference control registers Disadvantages:Caching a device control register would be disastrous unless the hardware supports selective cachingIf there is only one address space, then all memory modules and all I/O devices must examine all memory references to see which ones to respond toSingle bus -> everyone look at every address Multiple buses ->Mark non memory ranges and forward to non memory buses.

14Direct memory access (DMA):15A special control unit is used to transfer block of data directly between an external device and the main memory, without intervention by the processor. This approach is called Direct Memory Access (DMA).A DMA module controls the exchange of data between main memory and an I/O module. The processor sends a request for the transfer of a block of data to the DMA module and is interrupted only after the entire block has been transferredDMA is the dominant form of transfer that must be supported by the operating system.The operating system can only use DMA if the hardware has a DMA controller, which most systems doSometimes this controller is integrated into disk controllers and other controllersrequires a separate DMA controller for each device. More commonly, a single DMA controller is available (e.g., on the parent board) for regulating transfers to multiple devices, often concurrently

15Direct Memory Access16Disk read without DMA:The device controllerreads the block from the drive serially, bit by bit, until the entire block is in the controllers internal buffercomputes the checksum to verify that no read errors have occurred causes an interruptThe operating system starts runningread the disk block from the controllers buffer a byte or a word at a time by executing a loop and store in memory 16Direct Memory Access17With DMA:First the CPU programs the DMA controller by setting its registers so it knows what to transfer whereCPU also issues a command to the disk controller telling it to read data and verify the checksumThe DMA controller initiates the transfer by issuing a read request over the bus to the disk controllerWhen the write is complete, the disk controller sends an acknowledgement signal to the disk controller Then DMA controller interrupts the CPU to let it know that the transfer is now complete When the operating system starts up, it does not have to copy the disk block to memory; it is already there 17Direct Memory Access18

18INPUT/OUTPUTI/O devicesI/O softwareOrganization of I/O functionsDisk schedulingClocksCHAPTER FIVE1919 I/O Software 20Goals of I/O software design:device independenceit should be possible to write programs that can access any I/O device without having to specify the deviceuniform naming. The name of a file or a device should not depend on the device in any way error handling. errors should be handled as close to the hardware as possiblesynchronous (blocking) versus asynchronous (interrupt-driven)User programs are much easier to write if the I/O operations are blocking operating system to make operations that are actually interrupt-driven look blocking to the user programs.Some other issuesBufferingDedicated vs Sharable devices20I/O Software 21Programmed I/O The simplest form of I/O is to have the CPU do all the workThe operating system then (usually) copies the buffer with the string to an array, say, p, in kernel space, where it is more easily accessed (because the kernel may have to change the memory map to get at user space). It then checks to see if the I/O is currently available. If not, it waits until it is available. As soon as the I/O is available, the operating system copies the first character to the printers data register, in this example using memory-mapped I/O. 21I/O Software 22Programmed I/OConsider a user process that wants to print the eight-character string ABCDEFGH on the printer

22I/O Software 23Programmed I/OFirst the data are copied to the kernel. Then the operating system enters a tight loop outputting the characters one at a time. The essential aspect of programmed I/O, clearly illustrated in this figure, is that after outputting a character, the CPU continuously polls the device to see if it is ready to accept another one. This behavior is often called polling or busy waiting The processor issues an I/O command, on behalf of a process, to an I/O module; that process then busy waits for the operation to be completed before proceeding23I/O Software 24

Disadvantages:Tying up the CPU in busy waiting

24I/O Software 25Interrupt-Driven I/OThe processor issues an I/O command on behalf of a process and continues with other activitiesNonblocking instruction processor continues to execute instructions from the process that issued the I/O commandBlocking instruction put the current process in a blocked state and schedule another process to runWhen the data is ready, the processor is interrupted and handles the transferNow let us consider the case of printing on a printer that does not buffer characters but prints each one as it arrives25I/O Software 26

Send a character to the buffer and continueAfter interruptDisadvantage:Handling interrupt after every charProcessor is involved in the data transfer26I/O Software 27I/O Using DMA A DMA module controls the exchange of data between main memory and an I/O module. The processor sends a request for the transfer of a block of data to the DMA module and is interrupted only after the entire block has been transferredLets consider the printing again:let the DMA controller feed the characters to the printer one at time, without the CPU being botheredInterrupt the CPU after the entire data has been printed27I/O Software 28

Initiate printingHandling Interrupt 28INPUT/OUTPUTI/O devicesI/O softwareOrganization of I/O functionsDisk schedulingClocksCHAPTER FIVE2929I/O Software Layers30 I/O software is typically organized in four layers,

Organization of I/O functions30Device drivers31Each I/O device attached to a computer needs some device-specific code for controlling it, called device driverDevice drivers are generally written by the devices manufacturer and delivered along with the devices.Each device driver normally handles one device type, or at most, one class of closely related devicesIn order to access the devices hardware, meaning the controllers registers, the device driver normally has to be part of the operating system kernelOperating systems need to have an architecture that allows such installation 31Device drivers32Functions:accept abstract read and write requests from the device-independent software above it and see that they are carried out checking the input parameters to see if they are valid and convert them from abstract to concrete terms, e.g. in disks from block number to actual head, sector, track and cylinder numbersCheck device status if the operation can be applied, otherwise queue the requestControlling the device: issuing sequence of commands32Device driver33

33Device-Independent I/O Software 34The boundary between device-independent I/O software and device driver is system dependentsome functions that could be done in a device-independent way may actually be done in the drivers, for efficiency or other reasons.The basic function of the device-independent software is to perform the I/O functions that are common to all devices and to provide a uniform interface to the user-level software34Device-Independent I/O Software 35Typical functions:Uniform interfacing for device driversmake all I/O devices and drivers look more-or-less the same: Interface for device-driver, Name, protectionBufferingcreate a buffer inside the kernel and have the interrupt handler put the characters there Error reportingMany errors are device-specific and must be handled by the appropriate driver, but the framework for error handling is device independent Allocating and releasing dedicated devicesProviding a device-independent block size35User-Space I/O Software 36Most of the I/O software is within the operating system Consists of libraries linked together with user programsSystem calls are normally made by library procedures write(filePointer, varBuffer, nobytes); Library procedure write will be linked with the program and contained in the binary program present in memory at run time 36I/O Software Layers37 Layers of the I/O system and the main functions of each layer

37INPUT/OUTPUTI/O devicesI/O softwareOrganization of I/O functionsDisk schedulingClocksCHAPTER FIVE3838Disk Structure39Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.

The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially.Sector 0 is the first sector of the first track on the outermost cylinder.Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.

Disk scheduling3940

Disk StructureDisk Structure41

Arm Assembly41Disk Structure42

42Disk Arm Scheduling43The operating system is responsible for using hardware efficiently for the disk drives, this means having a fast access time and disk bandwidth.Access time has two major componentsSeek time is the time for the disk to move the heads to the cylinder containing the desired sector.Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head.Minimize seek timeSeek time seek distanceDisk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer.43Disk Arm Scheduling44Time required to read or write a disk block determined by 3 factorsSeek timeRotational delayActual transfer timeSeek time dominatesError checking is done by controllers4445READING ASSIGNMENT Disk Arm SchedulingC-SCANC-LOOK

RAID and its Level 45INPUT/OUTPUT I/O devices I/O software Organization of I/O functions Disk scheduling ClocksCHAPTER FIVE4646Clock47Clocks (or timers) are essential to the operation of any multiprogrammed system:maintain the time of day prevent one process from monopolizing the CPUSet a timer to trigger operation X at time TClocks take the same form as the other devices:HardwareSoftwareClocks47Clock Hardware48Programmable clocks typically have several modes of operationone-shot modeCopy value of holding register, decrement counter for every pulse and interruptWait until explicitly restarted square-wave modeafter getting to zero and causing the interrupt, the holding register is automatically copied into the counter, and the whole process is repeated again indefinitely. These periodic interrupts are called clock ticks 48Clock Hardware49All the clock hardware does is generate interrupts at known intervals.Everything else involving time must be done by the software, the clock driver:Maintaining the time of day (also called the real time) Preventing processes from running longer than they are allowed to. Accounting for CPU usage. Handling the alarm system call made by user processes. Providing watchdog timers for parts of the system itself. Doing profiling, monitoring, and statistics gathering. 49