《operatingsystem《操作系统》ch13-iosystem.ppt》由会员分享,可在线阅读,更多相关《operatingsystem《操作系统》ch13-iosystem.ppt(38页珍藏版)》请在三一办公上搜索。
1、Chapter 13:I/O Systems,Chapter 13:I/O Systems,I/O HardwareApplication I/O InterfaceKernel I/O SubsystemTransforming I/O Requests to Hardware OperationsStreamsPerformance,Objectives,Explore the structure of an operating systems I/O subsystemDiscuss the principles of I/O hardware and its complexityPro
2、vide details of the performance aspects of I/O hardware and software,I/O Hardware,Incredible variety of I/O devicesCommon conceptsPort Bus(daisy chain or shared direct access)Controller(host adapter)I/O instructions control devicesDevices have addresses,used by Direct I/O instructionsMemory-mapped I
3、/O,A Typical PC Bus Structure,Device I/O Port Locations on PCs(partial),Polling,Determines state of device command-readybusyErrorBusy-wait cycle to wait for I/O from device,Interrupts,CPU Interrupt-request line triggered by I/O deviceInterrupt handler receives interruptsMaskable to ignore or delay s
4、ome interruptsInterrupt vector to dispatch interrupt to correct handlerBased on prioritySome nonmaskableInterrupt mechanism also used for exceptions,Interrupt-Driven I/O Cycle,Intel Pentium Processor Event-Vector Table,Direct Memory Access,Used to avoid programmed I/O for large data movement Require
5、s DMA controllerBypasses CPU to transfer data directly between I/O device and memory,Six Step Process to Perform DMA Transfer,Application I/O Interface,I/O system calls encapsulate device behaviors in generic classesDevice-driver layer hides differences among I/O controllers from kernelDevices vary
6、in many dimensionsCharacter-stream or blockSequential or random-accessSharable or dedicatedSpeed of operationread-write,read only,or write only,A Kernel I/O Structure,Characteristics of I/O Devices,Block and Character Devices,Block devices include disk drivesCommands include read,write,seek Raw I/O
7、or file-system accessMemory-mapped file access possibleCharacter devices include keyboards,mice,serial portsCommands include get,putLibraries layered on top allow line editing,Network Devices,Varying enough from block and character to have own interfaceUnix and Windows NT/9x/2000 include socket inte
8、rfaceSeparates network protocol from network operationIncludes select functionalityApproaches vary widely(pipes,FIFOs,streams,queues,mailboxes),Clocks and Timers,Provide current time,elapsed time,timerProgrammable interval timer used for timings,periodic interruptsioctl(on UNIX)covers odd aspects of
9、 I/O such as clocks and timers,Blocking and Nonblocking I/O,Blocking-process suspended until I/O completedEasy to use and understandInsufficient for some needsNonblocking-I/O call returns as much as availableUser interface,data copy(buffered I/O)Implemented via multi-threadingReturns quickly with co
10、unt of bytes read or writtenAsynchronous-process runs while I/O executesDifficult to useI/O subsystem signals process when I/O completed,Two I/O Methods,Synchronous,Asynchronous,Kernel I/O Subsystem,SchedulingSome I/O request ordering via per-device queueSome OSs try fairnessBuffering-store data in
11、memory while transferring between devicesTo cope with device speed mismatchTo cope with device transfer size mismatchTo maintain“copy semantics”,Device-status Table,Sun Enterprise 6000 Device-Transfer Rates,Kernel I/O Subsystem,Caching-fast memory holding copy of dataAlways just a copyKey to perform
12、anceSpooling-hold output for a deviceIf device can serve only one request at a time i.e.,PrintingDevice reservation-provides exclusive access to a deviceSystem calls for allocation and deallocationWatch out for deadlock,Error Handling,OS can recover from disk read,device unavailable,transient write
13、failuresMost return an error number or code when I/O request fails System error logs hold problem reports,I/O Protection,User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructionsAll I/O instructions defined to be privilegedI/O must be performed vi
14、a system callsMemory-mapped and I/O port memory locations must be protected too,Use of a System Call to Perform I/O,Kernel Data Structures,Kernel keeps state info for I/O components,including open file tables,network connections,character device stateMany,many complex data structures to track buffer
15、s,memory allocation,“dirty”blocksSome use object-oriented methods and message passing to implement I/O,UNIX I/O Kernel Structure,I/O Requests to Hardware Operations,Consider reading a file from disk for a process:Determine device holding file Translate name to device representationPhysically read da
16、ta from disk into bufferMake data available to requesting processReturn control to process,Life Cycle of An I/O Request,STREAMS,STREAM a full-duplex communication channel between a user-level process and a device in Unix System V and beyondA STREAM consists of:-STREAM head interfaces with the user p
17、rocess-driver end interfaces with the device-zero or more STREAM modules between them.Each module contains a read queue and a write queueMessage passing is used to communicate between queues,The STREAMS Structure,Performance,I/O a major factor in system performance:Demands CPU to execute device driv
18、er,kernel I/O codeContext switches due to interruptsData copyingNetwork traffic especially stressful,Intercomputer Communications,Improving Performance,Reduce number of context switchesReduce data copying Reduce interrupts by using large transfers,smart controllers,polling Use DMABalance CPU,memory,bus,and I/O performance for highest throughput,Device-Functionality Progression,End of Chapter 13,